Skip to main content

Encoder

Struct Encoder 

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

A streaming encoder for any Format.

§Examples

use compress_lib::{Encoder, Format, Level, deflate::Flush, gzip};

let mut enc = Encoder::new(Format::Gzip, Level::DEFAULT);
let mut out = Vec::new();
enc.compress_vec(b"response body", &mut out, Flush::Finish)?;
assert_eq!(gzip::decompress(&out)?, b"response body");

Implementations§

Source§

impl Encoder

Source

pub fn new(format: Format, level: Level) -> Self

An encoder for format at level.

§Examples
use compress_lib::{Encoder, Format, Level};

assert_eq!(Encoder::new(Format::Zlib, Level::FAST).format(), Format::Zlib);
Source

pub fn format(&self) -> Format

The format written.

§Examples
use compress_lib::{Encoder, Format, Level};

assert_eq!(Encoder::new(Format::Raw, Level::FAST).format(), Format::Raw);
Source

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

As Deflater::compress, with the format’s header and trailer.

§Errors

As Deflater::compress.

§Examples
use compress_lib::{Encoder, Format, Level, deflate::{Flush, Status}};

let mut enc = Encoder::new(Format::Zlib, Level::DEFAULT);
let mut out = [0u8; 64];
assert_eq!(enc.compress(b"abc", &mut out, Flush::Finish)?.status, Status::Done);
Source

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

As Deflater::compress_vec.

§Errors

As compress, plus AllocationFailed.

§Examples
use compress_lib::{Encoder, Format, Level, deflate::Flush, zlib};

let mut out = Vec::new();
Encoder::new(Format::Zlib, Level::DEFAULT).compress_vec(b"abc", &mut out, Flush::Finish)?;
assert_eq!(zlib::decompress(&out)?, b"abc");
Source

pub fn reset(&mut self)

Starts a new stream, keeping allocations.

§Examples
let mut enc = compress_lib::Encoder::new(compress_lib::Format::Gzip, compress_lib::Level::FAST);
enc.reset();

Trait Implementations§

Source§

impl Debug for Encoder

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.