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
sourceimpl Compressor<'static>
impl Compressor<'static>
sourceimpl<'a> Compressor<'a>
impl<'a> Compressor<'a>
sourcepub fn with_prepared_dictionary<'b>(
dictionary: &'a EncoderDictionary<'b>
) -> Result<Self> where
'b: 'a,
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.
sourcepub fn set_compression_level(&mut self, level: i32) -> Result<()>
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.
sourcepub fn set_dictionary(&mut self, level: i32, dictionary: &[u8]) -> Result<()>
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.
sourcepub fn set_prepared_dictionary<'b>(
&mut self,
dictionary: &'a EncoderDictionary<'b>
) -> Result<()> where
'b: 'a,
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.
sourcepub fn compress_to_buffer<C: WriteBuf + ?Sized>(
&mut self,
source: &[u8],
destination: &mut C
) -> Result<usize>
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
).
sourcepub fn compress(&mut self, data: &[u8]) -> Result<Vec<u8>>
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
).
sourcepub fn context_mut(&mut self) -> &mut CCtx<'a>
pub fn context_mut(&mut self) -> &mut CCtx<'a>
Gives mutable access to the internal context.
sourcepub fn set_parameter(&mut self, parameter: CParameter) -> Result<()>
pub fn set_parameter(&mut self, parameter: CParameter) -> Result<()>
Sets a compression parameter for this compressor.
sourcepub fn include_checksum(&mut self, include_checksum: bool) -> Result<()>
pub fn include_checksum(&mut self, include_checksum: bool) -> Result<()>
Controls whether zstd should include a content checksum at the end of each frame.
sourcepub fn include_dictid(&mut self, include_dictid: bool) -> Result<()>
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.
sourcepub fn include_contentsize(&mut self, include_contentsize: bool) -> Result<()>
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
.
sourcepub fn long_distance_matching(
&mut self,
long_distance_matching: bool
) -> Result<()>
pub fn long_distance_matching(
&mut self,
long_distance_matching: bool
) -> Result<()>
Enables or disables long-distance matching
sourcepub fn window_log(&mut self, log_distance: u32) -> Result<()>
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
sourceimpl<'a> Default for Compressor<'a>
impl<'a> Default for Compressor<'a>
sourcefn default() -> Compressor<'a>
fn default() -> Compressor<'a>
Returns the “default value” for a type. Read more
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more