zstd::bulk

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

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.