Struct CCtx
struct CCtx<'a>(_, _)
Compression context
It is recommended to allocate a single context per thread and re-use it for many compression operations.
Implementations
impl<'a> CCtx<'a>
fn try_create() -> Option<Self>Tries to create a new context.
Returns
Noneif zstd returns a NULL pointer - may happen if allocation fails.fn create() -> SelfWrap
ZSTD_createCCtxPanics
If zstd returns a NULL pointer.
fn compress<C: WriteBuf + ?Sized>(self: &mut Self, dst: &mut C, src: &[u8], compression_level: CompressionLevel) -> SafeResultWraps the
ZSTD_compressCCtx()functionfn compress2<C: WriteBuf + ?Sized>(self: &mut Self, dst: &mut C, src: &[u8]) -> SafeResultWraps the
ZSTD_compress2()function.fn compress_using_dict<C: WriteBuf + ?Sized>(self: &mut Self, dst: &mut C, src: &[u8], dict: &[u8], compression_level: CompressionLevel) -> SafeResultWraps the
ZSTD_compress_usingDict()function.fn compress_using_cdict<C: WriteBuf + ?Sized>(self: &mut Self, dst: &mut C, src: &[u8], cdict: &CDict<'_>) -> SafeResultWraps the
ZSTD_compress_usingCDict()function.fn init(self: &mut Self, compression_level: CompressionLevel) -> SafeResultInitializes the context with the given compression level.
This is equivalent to running:
reset()set_parameter(CompressionLevel, compression_level)
fn load_dictionary(self: &mut Self, dict: &[u8]) -> SafeResultTries to load a dictionary.
The dictionary content will be copied internally and does not need to be kept alive after calling this function.
If you need to use the same dictionary for multiple contexts, it may be more efficient to create a
CDictfirst, then loads that.The dictionary will apply to all compressed frames, until a new dictionary is set.
fn ref_cdict<'b>(self: &mut Self, cdict: &CDict<'b>) -> SafeResult where 'b: 'aWraps the
ZSTD_CCtx_refCDict()function.Dictionary must outlive the context.
fn disable_dictionary(self: &mut Self) -> SafeResultReturn to "no-dictionary" mode.
This will disable any dictionary/prefix previously registered for future frames.
fn ref_prefix<'b>(self: &mut Self, prefix: &'b [u8]) -> SafeResult where 'b: 'aUse some prefix as single-use dictionary for the next compressed frame.
Just like a dictionary, decompression will need to be given the same prefix.
This is best used if the "prefix" looks like the data to be compressed.
fn compress_stream<C: WriteBuf + ?Sized>(self: &mut Self, output: &mut OutBuffer<'_, C>, input: &mut InBuffer<'_>) -> SafeResultPerforms a step of a streaming compression operation.
This will read some data from
inputand/or write some data tooutput.Returns
A hint for the "ideal" amount of input data to provide in the next call.
This hint is only for performance purposes.
Wraps the
ZSTD_compressStream()function.fn compress_stream2<C: WriteBuf + ?Sized>(self: &mut Self, output: &mut OutBuffer<'_, C>, input: &mut InBuffer<'_>, end_op: ZSTD_EndDirective) -> SafeResultPerforms a step of a streaming compression operation.
This will read some data from
inputand/or write some data tooutput.The
end_opdirective can be used to specify what to do after: nothing special, flush internal buffers, or end the frame.Returns
An lower bound for the amount of data that still needs to be flushed out.
This is useful when flushing or ending the frame: you need to keep calling this function until it returns 0.
Wraps the
ZSTD_compressStream2()function.fn flush_stream<C: WriteBuf + ?Sized>(self: &mut Self, output: &mut OutBuffer<'_, C>) -> SafeResultFlush any intermediate buffer.
To fully flush, you should keep calling this function until it returns
Ok(0).Wraps the
ZSTD_flushStream()function.fn end_stream<C: WriteBuf + ?Sized>(self: &mut Self, output: &mut OutBuffer<'_, C>) -> SafeResultEnds the stream.
You should keep calling this function until it returns
Ok(0).Wraps the
ZSTD_endStream()function.fn sizeof(self: &Self) -> usizeReturns the size currently used by this context.
This may change over time.
fn reset(self: &mut Self, reset: ResetDirective) -> SafeResultResets the state of the context.
Depending on the reset mode, it can reset the session, the parameters, or both.
Wraps the
ZSTD_CCtx_reset()function.fn set_parameter(self: &mut Self, param: CParameter) -> SafeResultSets a compression parameter.
Some of these parameters need to be set during de-compression as well.
fn set_pledged_src_size(self: &mut Self, pledged_src_size: Option<u64>) -> SafeResultGuarantee that the input size will be this value.
If given
None, assumes the size is unknown.Unless explicitly disabled, this will cause the size to be written in the compressed frame header.
If the actual data given to compress has a different size, an error will be returned.
fn in_size() -> usizeReturns the recommended input buffer size.
Using this size may result in minor performance boost.
fn out_size() -> usizeReturns the recommended output buffer size.
Using this may result in minor performance boost.
impl Default for CCtx<'_>
fn default() -> Self
impl Send for CCtx<'_>
impl Sync for CCtx<'_>
impl<'a> Drop for CCtx<'a>
fn drop(self: &mut Self)
impl<'a> Freeze for CCtx<'a>
impl<'a> RefUnwindSafe for CCtx<'a>
impl<'a> Unpin for CCtx<'a>
impl<'a> UnsafeUnpin for CCtx<'a>
impl<'a> UnwindSafe for CCtx<'a>
impl<T> Any for CCtx<'a>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for CCtx<'a>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for CCtx<'a>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for CCtx<'a>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for CCtx<'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 CCtx<'a>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for CCtx<'a>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>