pub fn compress(&self, stream: &mut Vec<u8>) -> Result<(), Error> {
        match *self {
            Codec::Null => (),
            Codec::Deflate => {
                let mut encoder = Encoder::new(Vec::new());
                encoder.write_all(stream)?;
                *stream = encoder.finish().into_result()?;
            }
            #[cfg(feature = "snappy")]
            Codec::Snappy => {
                use byteorder::ByteOrder;

                let mut encoded: Vec<u8> = vec![0; snap::max_compress_len(stream.len())];
                let compressed_size =
                    snap::Encoder::new().compress(&stream[..], &mut encoded[..])?;

                let crc = crc::crc32::checksum_ieee(&stream[..]);
                byteorder::BigEndian::write_u32(&mut encoded[compressed_size..], crc);
                encoded.truncate(compressed_size + 4);

                *stream = encoded;
            }
        };

        Ok(())
    }
/// Compress a stream of bytes in-place.
Compress a stream of bytes in-place.
Compress a stream of bytes in - place .
pub fn compress(&self, stream: &mut Vec<u8>) -> Result<(), Error> {
        match *self {
            Codec::Null => (),
            Codec::Deflate => {
                let mut encoder = Encoder::new(Vec::new());
                encoder.write_all(stream)?;
                *stream = encoder.finish().into_result()?;
            }
            #[cfg(feature = "snappy")]
            Codec::Snappy => {
                use byteorder::ByteOrder;
                let mut encoded: Vec<u8> = vec![0; snap::max_compress_len(stream.len())];
                let compressed_size =
                    snap::Encoder::new().compress(&stream[..], &mut encoded[..])?;
                let crc = crc::crc32::checksum_ieee(&stream[..]);
                byteorder::BigEndian::write_u32(&mut encoded[compressed_size..], crc);
                encoded.truncate(compressed_size + 4);
                *stream = encoded;
            }
        };
        Ok(())
    }
pub fn compress ( & self , stream : & mut Vec < u8 > ) -> Result < ( ) , Error > { match * self { Codec :: Null => ( ) , Codec :: Deflate => { let mut encoder = Encoder :: new ( Vec :: new ( ) ) ; encoder . write_all ( stream ) ? ; * stream = encoder . finish ( ) . into_result ( ) ? ; } # [ cfg ( feature " " ) ] Codec :: Snappy => { use byteorder :: ByteOrder ; let mut encoded : Vec < u8 > = vec ! [ 0 snap max_compress_len ( stream len ( ) ) ] ; let compressed_size = snap :: Encoder :: new ( ) . compress ( & stream [ .. ] , & mut encoded [ .. ] ) ? ; let crc = crc :: crc32 :: checksum_ieee ( & stream [ .. ] ) ; byteorder :: BigEndian :: write_u32 ( & mut encoded [ compressed_size .. ] , crc ) ; encoded . truncate ( compressed_size + 4 ) ; * stream = encoded ; } } ; Ok ( ( ) ) }
Compress a stream of bytes in-place.
Compress a stream of bytes in - place .
&self
stream
&mut Vec<u8>