pub fn compress(src: &[u8], algorithm: Algorithm) -> Result<(Cow<[u8]>, bool)> {
    let src_size = src.len();
    if src_size == 0 {
        return Ok((Cow::Borrowed(src), false));
    }
    match algorithm {
        Algorithm::None => Ok((Cow::Borrowed(src), false)),
        Algorithm::LZ4Block => {
            let compressed = lz4_compress(src)?;
            // Abandon compressed data when compression ratio greater than COMPRESSION_MINIMUM_RATIO
            if (COMPRESSION_MINIMUM_RATIO == 100 && compressed.len() >= src_size)
                || ((100 * compressed.len() / src_size) >= COMPRESSION_MINIMUM_RATIO)
            {
                return Ok((Cow::Borrowed(src), false));
            }
            Ok((Cow::Owned(compressed), true))
        }
    }
}
// For compatibility reason, we use liblz4 version to compress/decompress directly
// with data blocks so that we don't really care about lz4 header magic numbers like
// as being done with all these rust lz4 implementations
For compatibility reason, we use liblz4 version to compress/decompress directly
with data blocks so that we don't really care about lz4 header magic numbers like
as being done with all these rust lz4 implementations
For compatibility reason we use liblz4 version to compress / decompress directly with data blocks so that we don ' t really care about lz4 header magic numbers like as being done with all these rust lz4 implementations
pub fn compress(src: &[u8], algorithm: Algorithm) -> Result<(Cow<[u8]>, bool)> {
    let src_size = src.len();
    if src_size == 0 {
        return Ok((Cow::Borrowed(src), false));
    }
    match algorithm {
        Algorithm::None => Ok((Cow::Borrowed(src), false)),
        Algorithm::LZ4Block => {
            let compressed = lz4_compress(src)?;
            // Abandon compressed data when compression ratio greater than COMPRESSION_MINIMUM_RATIO
            if (COMPRESSION_MINIMUM_RATIO == 100 && compressed.len() >= src_size)
                || ((100 * compressed.len() / src_size) >= COMPRESSION_MINIMUM_RATIO)
            {
                return Ok((Cow::Borrowed(src), false));
            }
            Ok((Cow::Owned(compressed), true))
        }
    }
}
pub fn compress ( src : & [ u8 ] , algorithm : Algorithm ) -> Result < ( Cow < [ u8 ] > , bool ) > { let src_size = src . len ( ) ; if src_size == 0 { return Ok ( ( Cow :: Borrowed ( src ) , false ) ) ; } match algorithm { Algorithm :: None => Ok ( ( Cow :: Borrowed ( src ) , false ) ) , Algorithm :: LZ4Block => { let compressed = lz4_compress ( src ) ? ; // Abandon compressed data when compression ratio greater than COMPRESSION_MINIMUM_RATIO if ( COMPRESSION_MINIMUM_RATIO == 100 && compressed . len ( ) >= src_size ) || ( ( 100 * compressed . len ( ) / src_size ) >= COMPRESSION_MINIMUM_RATIO ) { return Ok ( ( Cow :: Borrowed ( src ) , false ) ) ; } Ok ( ( Cow :: Owned ( compressed ) , true ) ) } } }
For compatibility reason, we use liblz4 version to compress/decompress directly
with data blocks so that we don't really care about lz4 header magic numbers like
as being done with all these rust lz4 implementations
For compatibility reason we use liblz4 version to compress / decompress directly with data blocks so that we don ' t really care about lz4 header magic numbers like as being done with all these rust lz4 implementations
src
&[u8]
algorithm
Algorithm
src
&[u8]
algorithm
Algorithm