pub fn append(&mut self, buffer: &[u8]) -> io::Result<()> {
        if buffer.len() > self.buffer.len() - self.size {
            if self.is_expandable() {
                // Extend the buffer
                let size = max(
                    (self.buffer.len() as f64 * EXPANSION_FACTOR) as usize,
                    self.buffer.len() + buffer.len(),
                );

                let mut new_buffer = vec![0u8; size];

                // From the head to the end of the buffer
                let length_a = min(self.size, self.buffer.len() - self.head);
                new_buffer[..length_a]
                    .copy_from_slice(&self.buffer[self.head..self.head + length_a]);

                // From the begin of the buffer to the tail
                let length_b = self.size - length_a;
                if length_b > 0 {
                    new_buffer[length_a..length_a + length_b]
                        .copy_from_slice(&self.buffer[..length_b]);
                }

                self.buffer = new_buffer;
                self.head = 0;
            } else {
                return Err(io::Error::new(io::ErrorKind::Other, "cache is full"));
            }
        }

        // From the tail to the end of the buffer
        let mut length_a = 0;
        if self.head + self.size < self.buffer.len() {
            length_a = min(buffer.len(), self.buffer.len() - (self.head + self.size));
            self.buffer[self.head + self.size..self.head + self.size + length_a]
                .copy_from_slice(&buffer[..length_a]);
        }

        // From the begin of the buffer to the head
        let length_b = buffer.len() - length_a;
        if length_b > 0 {
            self.buffer[..length_b].copy_from_slice(&buffer[length_a..]);
        }

        self.size += buffer.len();

        Ok(())
    }
/// Appends some bytes to the end of the cache.
Appends some bytes to the end of the cache.
Appends some bytes to the end of the cache .
pub fn append(&mut self, buffer: &[u8]) -> io::Result<()> {
        if buffer.len() > self.buffer.len() - self.size {
            if self.is_expandable() {
                // Extend the buffer
                let size = max(
                    (self.buffer.len() as f64 * EXPANSION_FACTOR) as usize,
                    self.buffer.len() + buffer.len(),
                );
                let mut new_buffer = vec![0u8; size];
                // From the head to the end of the buffer
                let length_a = min(self.size, self.buffer.len() - self.head);
                new_buffer[..length_a]
                    .copy_from_slice(&self.buffer[self.head..self.head + length_a]);
                // From the begin of the buffer to the tail
                let length_b = self.size - length_a;
                if length_b > 0 {
                    new_buffer[length_a..length_a + length_b]
                        .copy_from_slice(&self.buffer[..length_b]);
                }
                self.buffer = new_buffer;
                self.head = 0;
            } else {
                return Err(io::Error::new(io::ErrorKind::Other, "cache is full"));
            }
        }
        // From the tail to the end of the buffer
        let mut length_a = 0;
        if self.head + self.size < self.buffer.len() {
            length_a = min(buffer.len(), self.buffer.len() - (self.head + self.size));
            self.buffer[self.head + self.size..self.head + self.size + length_a]
                .copy_from_slice(&buffer[..length_a]);
        }
        // From the begin of the buffer to the head
        let length_b = buffer.len() - length_a;
        if length_b > 0 {
            self.buffer[..length_b].copy_from_slice(&buffer[length_a..]);
        }
        self.size += buffer.len();
        Ok(())
    }
pub fn append ( & mut self , buffer : & [ u8 ] ) -> io :: Result < ( ) > { if buffer . len ( ) > self . buffer . len ( ) - self . size { if self . is_expandable ( ) { // Extend the buffer let size = max ( ( self . buffer . len ( ) as f64 * EXPANSION_FACTOR ) as usize , self . buffer . len ( ) + buffer . len ( ) , ) ; let mut new_buffer = vec ! [ 0u8 size ] ; // From the head to the end of the buffer let length_a = min ( self . size , self . buffer . len ( ) - self . head ) ; new_buffer [ .. length_a ] . copy_from_slice ( & self . buffer [ self . head .. self . head + length_a ] ) ; // From the begin of the buffer to the tail let length_b = self . size - length_a ; if length_b > 0 { new_buffer [ length_a .. length_a + length_b ] . copy_from_slice ( & self . buffer [ .. length_b ] ) ; } self . buffer = new_buffer ; self . head = 0 ; } else { return Err ( io :: Error :: new ( io :: ErrorKind :: Other , " " ) ) ; } } // From the tail to the end of the buffer let mut length_a = 0 ; if self . head + self . size < self . buffer . len ( ) { length_a = min ( buffer . len ( ) , self . buffer . len ( ) - ( self . head + self . size ) ) ; self . buffer [ self . head + self . size .. self . head + self . size + length_a ] . copy_from_slice ( & buffer [ .. length_a ] ) ; } // From the begin of the buffer to the head let length_b = buffer . len ( ) - length_a ; if length_b > 0 { self . buffer [ .. length_b ] . copy_from_slice ( & buffer [ length_a .. ] ) ; } self . size += buffer . len ( ) ; Ok ( ( ) ) }
Appends some bytes to the end of the cache.
Appends some bytes to the end of the cache .
&mut self
buffer
&[u8]