pub fn decompress_block(
    block: &mut CompressedBlock,
    decompressed: &mut Block,
    compression: Option<Compression>,
) -> Result<bool> {
    decompressed.number_of_rows = block.number_of_rows;
    let block = &mut block.data;
    let decompressed = &mut decompressed.data;

    match compression {
        None => {
            std::mem::swap(block, decompressed);
            Ok(true)
        }
        #[cfg(feature = "io_avro_compression")]
        Some(Compression::Deflate) => {
            decompressed.clear();
            let mut decoder = libflate::deflate::Decoder::new(&block[..]);
            decoder.read_to_end(decompressed)?;
            Ok(false)
        }
        #[cfg(feature = "io_avro_compression")]
        Some(Compression::Snappy) => {
            let crc = &block[block.len() - 4..];
            let block = &block[..block.len() - 4];

            let len = snap::raw::decompress_len(block)
                .map_err(|e| ArrowError::ExternalFormat(e.to_string()))?;
            decompressed.clear();
            decompressed.resize(len, 0);
            snap::raw::Decoder::new()
                .decompress(block, decompressed)
                .map_err(|e| ArrowError::ExternalFormat(e.to_string()))?;

            let expected_crc = u32::from_be_bytes([crc[0], crc[1], crc[2], crc[3]]);
            let actual_crc = crc::crc32::checksum_ieee(decompressed);
            if expected_crc != actual_crc {
                return Err(ArrowError::ExternalFormat(
                    "The crc of snap-compressed block does not match".to_string(),
                ));
            }
            Ok(false)
        }
        #[cfg(not(feature = "io_avro_compression"))]
        Some(Compression::Deflate) => Err(ArrowError::InvalidArgumentError(
            "The avro file is deflate-encoded but feature 'io_avro_compression' is not active."
                .to_string(),
        )),
        #[cfg(not(feature = "io_avro_compression"))]
        Some(Compression::Snappy) => Err(ArrowError::InvalidArgumentError(
            "The avro file is snappy-encoded but feature 'io_avro_compression' is not active."
                .to_string(),
        )),
    }
}
/// Decompresses an Avro block.
/// Returns whether the buffers where swapped.
Decompresses an Avro block.
Returns whether the buffers where swapped.
Decompresses an Avro block . Returns whether the buffers where swapped .
pub fn decompress_block(
    block: &mut CompressedBlock,
    decompressed: &mut Block,
    compression: Option<Compression>,
) -> Result<bool> {
    decompressed.number_of_rows = block.number_of_rows;
    let block = &mut block.data;
    let decompressed = &mut decompressed.data;
    match compression {
        None => {
            std::mem::swap(block, decompressed);
            Ok(true)
        }
        #[cfg(feature = "io_avro_compression")]
        Some(Compression::Deflate) => {
            decompressed.clear();
            let mut decoder = libflate::deflate::Decoder::new(&block[..]);
            decoder.read_to_end(decompressed)?;
            Ok(false)
        }
        #[cfg(feature = "io_avro_compression")]
        Some(Compression::Snappy) => {
            let crc = &block[block.len() - 4..];
            let block = &block[..block.len() - 4];
            let len = snap::raw::decompress_len(block)
                .map_err(|e| ArrowError::ExternalFormat(e.to_string()))?;
            decompressed.clear();
            decompressed.resize(len, 0);
            snap::raw::Decoder::new()
                .decompress(block, decompressed)
                .map_err(|e| ArrowError::ExternalFormat(e.to_string()))?;
            let expected_crc = u32::from_be_bytes([crc[0], crc[1], crc[2], crc[3]]);
            let actual_crc = crc::crc32::checksum_ieee(decompressed);
            if expected_crc != actual_crc {
                return Err(ArrowError::ExternalFormat(
                    "The crc of snap-compressed block does not match".to_string(),
                ));
            }
            Ok(false)
        }
        #[cfg(not(feature = "io_avro_compression"))]
        Some(Compression::Deflate) => Err(ArrowError::InvalidArgumentError(
            "The avro file is deflate-encoded but feature 'io_avro_compression' is not active."
                .to_string(),
        )),
        #[cfg(not(feature = "io_avro_compression"))]
        Some(Compression::Snappy) => Err(ArrowError::InvalidArgumentError(
            "The avro file is snappy-encoded but feature 'io_avro_compression' is not active."
                .to_string(),
        )),
    }
}
pub fn decompress_block ( block : & mut CompressedBlock , decompressed : & mut Block , compression : Option < Compression > , ) -> Result < bool > { decompressed . number_of_rows = block . number_of_rows ; let block = & mut block . data ; let decompressed = & mut decompressed . data ; match compression { None => { std :: mem :: swap ( block , decompressed ) ; Ok ( true ) } # [ cfg ( feature " " ) ] Some ( Compression :: Deflate ) => { decompressed . clear ( ) ; let mut decoder = libflate :: deflate :: Decoder :: new ( & block [ .. ] ) ; decoder . read_to_end ( decompressed ) ? ; Ok ( false ) } # [ cfg ( feature " " ) ] Some ( Compression :: Snappy ) => { let crc = & block [ block . len ( ) - 4 .. ] ; let block = & block [ .. block . len ( ) - 4 ] ; let len = snap :: raw :: decompress_len ( block ) . map_err ( | e | ArrowError :: ExternalFormat ( e . to_string ( ) ) ) ? ; decompressed . clear ( ) ; decompressed . resize ( len , 0 ) ; snap :: raw :: Decoder :: new ( ) . decompress ( block , decompressed ) . map_err ( | e | ArrowError :: ExternalFormat ( e . to_string ( ) ) ) ? ; let expected_crc = u32 :: from_be_bytes ( [ crc [ 0 ] , crc [ 1 ] , crc [ 2 ] , crc [ 3 ] ] ) ; let actual_crc = crc :: crc32 :: checksum_ieee ( decompressed ) ; if expected_crc != actual_crc { return Err ( ArrowError :: ExternalFormat ( " " . to_string ( ) , ) ) ; } Ok ( false ) } # [ cfg ( not ( feature " " ) ) ] Some ( Compression :: Deflate ) => Err ( ArrowError :: InvalidArgumentError ( " " . to_string ( ) , ) ) , # [ cfg ( not ( feature " " ) ) ] Some ( Compression :: Snappy ) => Err ( ArrowError :: InvalidArgumentError ( " " . to_string ( ) , ) ) , } }
Decompresses an Avro block.
Decompresses an Avro block .
block
&mut CompressedBlock
decompressed
&mut Block
compression
Option<Compression>
block
&mut CompressedBlock
decompressed
&mut Block
compression
Option<Compression>