Struct Compressor
struct Compressor<'a> { ... }
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
Readinto a temporary buffer before compression.
Implementations
impl Compressor<'static>
fn new(level: i32) -> Result<Self>Creates a new zstd compressor
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.
impl<'a> Compressor<'a>
fn with_prepared_dictionary<'b>(dictionary: &'a EncoderDictionary<'b>) -> Result<Self> where 'b: 'aCreates 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.
fn set_compression_level(self: &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_dictionaryinstead of using this method.fn set_dictionary(self: &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.
fn set_prepared_dictionary<'b>(self: &mut Self, dictionary: &'a EncoderDictionary<'b>) -> Result<()> where 'b: 'aChanges 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.
fn compress_to_buffer<C: zstd_safe::WriteBuf + ?Sized>(self: &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
0uses zstd's default (currently3).fn compress(self: &mut Self, data: &[u8]) -> Result<Vec<u8>>Compresses a block of data and returns the compressed result.
A level of
0uses zstd's default (currently3).fn context_mut(self: &mut Self) -> &mut CCtx<'a>Gives mutable access to the internal context.
fn set_parameter(self: &mut Self, parameter: CParameter) -> Result<()>Sets a compression parameter for this compressor.
fn include_checksum(self: &mut Self, include_checksum: bool) -> Result<()>Controls whether zstd should include a content checksum at the end of each frame.
fn include_dictid(self: &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.
fn include_contentsize(self: &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.fn long_distance_matching(self: &mut Self, long_distance_matching: bool) -> Result<()>Enables or disables long-distance matching
fn set_target_cblock_size(self: &mut Self, target_size: Option<u32>) -> Result<()>Sets the target size for compressed blocks.
A lower block size may result in slightly lower speed (~2%) and compression ratio (~0.1%), but may decrease end-to-end latency in low-bandwidth environments (time to first decompressed byte).
No value, or a value of zero, results in no contraint for the block sizes.
fn window_log(self: &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.
impl<'a> Default for Compressor<'a>
fn default() -> Compressor<'a>
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> UnsafeUnpin for Compressor<'a>
impl<'a> UnwindSafe for Compressor<'a>
impl<T> Any for Compressor<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Compressor<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Compressor<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for Compressor<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for Compressor<'a>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Compressor<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Compressor<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>