pub struct DeflateDecoder<'a> { /* private fields */ }
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

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_gzip(&mut self) -> Result<Vec<u8>, InflateDecodeErrors>

Decode a gzip encoded data and return the uncompressed data 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 gzip 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();

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.