Struct zstd::bulk::Compressor

source ·
pub struct Compressor<'a> { /* private fields */ }
Expand description

Allows to compress independently multiple chunks of data.

Each job will be processed entirely in-memory without streaming, so this is most fitting for many small jobs. To compress larger volume that don’t easily fit in memory, a streaming compression may be more appropriate.

It is more efficient than a streaming compressor for 2 reasons:

  • It re-uses the zstd context between jobs to avoid re-allocations
  • It avoids copying data from a Read into a temporary buffer before compression.

Implementations§

source§

impl Compressor<'static>

source

pub fn new(level: i32) -> Result<Self>

Creates a new zstd compressor

source

pub fn with_dictionary(level: i32, dictionary: &[u8]) -> Result<Self>

Creates a new zstd compressor, using the given dictionary.

Note that using a dictionary means that decompression will need to use the same dictionary.

source§

impl<'a> Compressor<'a>

source

pub fn with_prepared_dictionary<'b>( dictionary: &'a EncoderDictionary<'b>, ) -> Result<Self>
where 'b: 'a,

Creates a new compressor using an existing EncoderDictionary.

The compression level will be the one specified when creating the dictionary.

Note that using a dictionary means that decompression will need to use the same dictionary.

source

pub fn set_compression_level(&mut self, level: i32) -> Result<()>

Changes the compression level used by this compressor.

This will clear any dictionary previously registered.

If you want to keep the existing dictionary, you will need to pass it again to Self::set_dictionary instead of using this method.

source

pub fn set_dictionary(&mut self, level: i32, dictionary: &[u8]) -> Result<()>

Changes the dictionary and compression level used by this compressor.

Will affect future compression jobs.

Note that using a dictionary means that decompression will need to use the same dictionary.

source

pub fn set_prepared_dictionary<'b>( &mut self, dictionary: &'a EncoderDictionary<'b>, ) -> Result<()>
where 'b: 'a,

Changes the dictionary used by this compressor.

The compression level used when preparing the dictionary will be used.

Note that using a dictionary means that decompression will need to use the same dictionary.

source

pub fn compress_to_buffer<C: WriteBuf + ?Sized>( &mut self, source: &[u8], destination: &mut C, ) -> Result<usize>

Compress a single block of data to the given destination buffer.

Returns the number of bytes written, or an error if something happened (for instance if the destination buffer was too small).

A level of 0 uses zstd’s default (currently 3).

source

pub fn compress(&mut self, data: &[u8]) -> Result<Vec<u8>>

Compresses a block of data and returns the compressed result.

A level of 0 uses zstd’s default (currently 3).

source

pub fn context_mut(&mut self) -> &mut CCtx<'a>

Gives mutable access to the internal context.

source

pub fn set_parameter(&mut self, parameter: CParameter) -> Result<()>

Sets a compression parameter for this compressor.

source

pub fn include_checksum(&mut self, include_checksum: bool) -> Result<()>

Controls whether zstd should include a content checksum at the end of each frame.

source

pub fn include_dictid(&mut self, include_dictid: bool) -> Result<()>

Enables or disables storing of the dict id.

Defaults to true. If false, the behaviour of decoding with a wrong dictionary is undefined.

source

pub fn include_contentsize(&mut self, include_contentsize: bool) -> Result<()>

Enables or disabled storing of the contentsize.

Note that this only has an effect if the size is given with set_pledged_src_size.

source

pub fn long_distance_matching( &mut self, long_distance_matching: bool, ) -> Result<()>

Enables or disables long-distance matching

source

pub fn window_log(&mut self, log_distance: u32) -> Result<()>

Sets the maximum back-reference distance.

The actual maximum distance is going to be 2^log_distance.

Note that decompression will need to use at least the same setting.

Trait Implementations§

source§

impl<'a> Default for Compressor<'a>

source§

fn default() -> Compressor<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Compressor<'a>

§

impl<'a> RefUnwindSafe for Compressor<'a>

§

impl<'a> Send for Compressor<'a>

§

impl<'a> !Sync for Compressor<'a>

§

impl<'a> Unpin for Compressor<'a>

§

impl<'a> UnwindSafe for Compressor<'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>,

§

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>,

§

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.