zune_inflate

Struct DeflateDecoder

source
pub struct DeflateDecoder<'a> {
    data: &'a [u8],
    position: usize,
    stream: BitStreamReader<'a>,
    is_last_block: bool,
    static_codes_loaded: bool,
    deflate_header_tables: DeflateHeaderTables,
    options: DeflateOptions,
}
Expand description

A deflate decoder instance.

The decoder manages output buffer as opposed to requiring the caller to provide a pre-allocated buffer it tracks number of bytes written and on successfully reaching the end of the block, will return a vector with exactly the number of decompressed bytes.

This means that it may use up huge amounts of memory if not checked, but there are options that can prevent that

Fields§

§data: &'a [u8]§position: usize§stream: BitStreamReader<'a>§is_last_block: bool§static_codes_loaded: bool§deflate_header_tables: DeflateHeaderTables§options: DeflateOptions

Implementations§

source§

impl<'a> DeflateDecoder<'a>

source

pub fn new(data: &'a [u8]) -> DeflateDecoder<'a>

Create a new decompressor that will read compressed data from data and return a new vector containing new data

§Arguments
  • data: The compressed data. Data can be of any type gzip,zlib or raw deflate.
§Returns

A decoder instance which will pull compressed data from data to inflate the output output

§Note

The default output size limit is 1 GiB. this is to protect the end user against ddos attacks as deflate does not specify it’s output size upfront

The checksum will be verified depending on the called function. this only works for zlib and gzip since deflate does not have a checksum

These defaults can be overridden via new_with_options().

source

pub fn new_with_options( data: &'a [u8], options: DeflateOptions, ) -> DeflateDecoder<'a>

Create new decoder with specified options

This can be used to fine tune the decoder to the user’s needs.

§Arguments
  • data: The compressed data. Data can be of any format i.e gzip, zlib or raw deflate.
  • options : A set of user defined options which tune how the decompressor
§Returns

A decoder instance which will pull compressed data from data to inflate output

§Example
use zune_inflate::{DeflateDecoder, DeflateOptions};
let data  = [37];
let options = DeflateOptions::default()
    .set_confirm_checksum(true) // confirm the checksum for zlib and gzip
    .set_limit(1000); // how big I think the input will be    
let mut decoder = DeflateDecoder::new_with_options(&data,options);
// do some stuff and then call decode
let data = decoder.decode_zlib();
source

pub fn decode_zlib(&mut self) -> Result<Vec<u8>, InflateDecodeErrors>

Decode zlib-encoded data returning the uncompressed in a Vec<u8> or an error if something went wrong.

Bytes consumed will be from the data passed when the new method was called.

§Arguments
  • None
§Returns

Result type containing the decoded data.

  • Ok(Vec<u8>): Decoded vector containing the uncompressed bytes
  • Err(InflateDecodeErrors): Error that occurred during decoding

It’s possible to recover bytes even after an error occurred, bytes up to when error was encountered are stored in InflateDecodeErrors

§Note

This needs the zlib feature enabled to be available otherwise it’s a compile time error

source

pub fn decode_deflate(&mut self) -> Result<Vec<u8>, InflateDecodeErrors>

Decode a deflate stream returning the data as Vec<u8> or an error indicating what went wrong.

§Arguments
  • None
§Returns

Result type containing the decoded data.

  • Ok(Vec<u8>): Decoded vector containing the uncompressed bytes
  • Err(InflateDecodeErrors): Error that occurred during decoding

It’s possible to recover bytes even after an error occurred, bytes up to when error was encountered are stored in InflateDecodeErrors

§Example
let data = [42]; // answer to life, the universe and everything

let mut decoder = zune_inflate::DeflateDecoder::new(&data);
let bytes = decoder.decode_deflate().unwrap();
source

fn start_deflate_block(&mut self) -> Result<Vec<u8>, InflateDecodeErrors>

Main inner loop for decompressing deflate data

source

fn build_decode_table( &mut self, block_type: u64, ) -> Result<(), DecodeErrorStatus>

Build decode tables for static and dynamic huffman blocks.

source

fn build_decode_table_inner( &mut self, lens: &[u8], decode_results: &[u32], decode_table: &mut [u32], table_bits: usize, num_syms: usize, max_codeword_len: usize, ) -> Result<(), DecodeErrorStatus>

Build the decode table for the precode

Auto Trait Implementations§

§

impl<'a> Freeze for DeflateDecoder<'a>

§

impl<'a> RefUnwindSafe for DeflateDecoder<'a>

§

impl<'a> Send for DeflateDecoder<'a>

§

impl<'a> Sync for DeflateDecoder<'a>

§

impl<'a> Unpin for DeflateDecoder<'a>

§

impl<'a> UnwindSafe for DeflateDecoder<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.