Struct flate2::mem::Compress

source ·
pub struct Compress {
    inner: Deflate,
}
Expand description

Raw in-memory compression stream for blocks of data.

This type is the building block for the I/O streams in the rest of this crate. It requires more management than the Read/Write API but is maximally flexible in terms of accepting input from any source and being able to produce output to any memory location.

It is recommended to use the I/O stream adaptors over this type as they’re easier to use.

Fields§

§inner: Deflate

Implementations§

source§

impl Compress

source

pub fn new(level: Compression, zlib_header: bool) -> Compress

Creates a new object ready for compressing data that it’s given.

The level argument here indicates what level of compression is going to be performed, and the zlib_header argument indicates whether the output data should have a zlib header or not.

source

pub fn total_in(&self) -> u64

Returns the total number of input bytes which have been processed by this compression object.

source

pub fn total_out(&self) -> u64

Returns the total number of output bytes which have been produced by this compression object.

source

pub fn reset(&mut self)

Quickly resets this compressor without having to reallocate anything.

This is equivalent to dropping this object and then creating a new one.

source

pub fn compress( &mut self, input: &[u8], output: &mut [u8], flush: FlushCompress, ) -> Result<Status, CompressError>

Compresses the input data into the output, consuming only as much input as needed and writing as much output as possible.

The flush option can be any of the available FlushCompress parameters.

To learn how much data was consumed or how much output was produced, use the total_in and total_out functions before/after this is called.

source

pub fn compress_vec( &mut self, input: &[u8], output: &mut Vec<u8>, flush: FlushCompress, ) -> Result<Status, CompressError>

Compresses the input data into the extra space of the output, consuming only as much input as needed and writing as much output as possible.

This function has the same semantics as compress, except that the length of vec is managed by this function. This will not reallocate the vector provided or attempt to grow it, so space for the output must be reserved in the output vector by the caller before calling this function.

Trait Implementations§

source§

impl Debug for Compress

source§

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

Formats the value using the given formatter. Read more
source§

impl Ops for Compress

source§

type Flush = FlushCompress

source§

fn total_in(&self) -> u64

source§

fn total_out(&self) -> u64

source§

fn run( &mut self, input: &[u8], output: &mut [u8], flush: FlushCompress, ) -> Result<Status, DecompressError>

source§

fn run_vec( &mut self, input: &[u8], output: &mut Vec<u8>, flush: FlushCompress, ) -> Result<Status, DecompressError>

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