Skip to main content

Decoder

Struct Decoder 

Source
pub struct Decoder(/* private fields */);
Expand description

A streaming decoder for any Format.

§Examples

use compress_lib::{Decoder, Format, gzip};

let mut dec = Decoder::new(Format::Gzip);
let mut out = Vec::new();
dec.finish_vec(&gzip::compress(b"any format"), &mut out)?;
assert_eq!(out, b"any format");

Implementations§

Source§

impl Decoder

Source

pub fn new(format: Format) -> Self

A decoder for format with the default limits.

§Examples
let dec = compress_lib::Decoder::new(compress_lib::Format::Zlib);
assert_eq!(dec.format(), compress_lib::Format::Zlib);
Source

pub fn with_limits(self, limits: Limits) -> Self

Sets the limits checked while decoding.

§Examples
use compress_lib::{Decoder, Format, Limits};

let dec = Decoder::new(Format::Gzip).with_limits(Limits::new().with_max_output(1 << 20));
Source

pub fn format(&self) -> Format

The format decoded.

§Examples
use compress_lib::{Decoder, Format};

assert_eq!(Decoder::new(Format::Raw).format(), Format::Raw);
Source

pub fn decompress( &mut self, input: &[u8], output: &mut [u8], ) -> Result<Progress, Error>

As Inflater::decompress.

§Errors

The errors of the format’s decoder.

§Examples
use compress_lib::{Decoder, Format, deflate::Status, zlib};

let mut out = [0u8; 16];
let p = Decoder::new(Format::Zlib).decompress(&zlib::compress(b"abc"), &mut out)?;
assert_eq!(p.status, Status::Done);
Source

pub fn finish( &mut self, input: &[u8], output: &mut [u8], ) -> Result<Progress, Error>

As Inflater::finish.

§Errors

The errors of the format’s decoder, plus UnexpectedEnd.

§Examples
use compress_lib::{Decoder, Format, gzip};

let mut out = [0u8; 16];
let p = Decoder::new(Format::Gzip).finish(&gzip::compress(b"abc"), &mut out)?;
assert_eq!(&out[..p.produced], b"abc");
Source

pub fn decompress_vec( &mut self, input: &[u8], out: &mut Vec<u8>, ) -> Result<Progress, Error>

As Inflater::decompress_vec.

§Errors

The errors of the format’s decoder, plus AllocationFailed.

§Examples
use compress_lib::{Decoder, Format, deflate};

let mut out = Vec::new();
Decoder::new(Format::Raw).decompress_vec(&deflate::compress(b"raw"), &mut out)?;
assert_eq!(out, b"raw");
Source

pub fn finish_vec( &mut self, input: &[u8], out: &mut Vec<u8>, ) -> Result<Progress, Error>

As Inflater::finish_vec.

§Errors

The errors of the format’s decoder, plus UnexpectedEnd and AllocationFailed.

§Examples
use compress_lib::{Decoder, Format, zlib};

let mut out = Vec::new();
Decoder::new(Format::Zlib).finish_vec(&zlib::compress(b"z"), &mut out)?;
assert_eq!(out, b"z");
Source

pub fn is_done(&self) -> bool

true once the stream ended.

§Examples
assert!(!compress_lib::Decoder::new(compress_lib::Format::Gzip).is_done());
Source

pub fn total_in(&self) -> u64

Compressed bytes consumed.

§Examples
assert_eq!(compress_lib::Decoder::new(compress_lib::Format::Gzip).total_in(), 0);
Source

pub fn total_out(&self) -> u64

Decompressed bytes produced.

§Examples
assert_eq!(compress_lib::Decoder::new(compress_lib::Format::Gzip).total_out(), 0);
Source

pub fn reset(&mut self)

Starts over for a new stream, keeping allocations.

§Examples
let mut dec = compress_lib::Decoder::new(compress_lib::Format::Zlib);
dec.reset();

Trait Implementations§

Source§

impl Debug for Decoder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.