Struct zstd_safe::DCtx

source ·
pub struct DCtx<'a>(/* private fields */);
Expand description

A Decompression Context.

The lifetime references the potential dictionary used for this context.

If no dictionary was used, it will most likely be 'static.

Same as DStream.

Implementations§

source§

impl<'a> DCtx<'a>

source

pub fn try_create() -> Option<Self>

Try to create a new decompression context.

Returns None if the operation failed (for example, not enough memory).

source

pub fn create() -> Self

Creates a new decoding context.

Panics

If the context creation fails.

source

pub fn decompress<C: WriteBuf + ?Sized>( &mut self, dst: &mut C, src: &[u8] ) -> SafeResult

Fully decompress the given frame.

This decompress an entire frame in-memory. If you can have enough memory to store both the input and output buffer, then it may be faster that streaming decompression.

Wraps the ZSTD_decompressDCtx() function.

source

pub fn decompress_using_dict<C: WriteBuf + ?Sized>( &mut self, dst: &mut C, src: &[u8], dict: &[u8] ) -> SafeResult

Fully decompress the given frame using a dictionary.

Dictionary must be identical to the one used during compression.

If you plan on using the same dictionary multiple times, it is faster to create a DDict first and use decompress_using_ddict.

Wraps ZSTD_decompress_usingDict

source

pub fn decompress_using_ddict<C: WriteBuf + ?Sized>( &mut self, dst: &mut C, src: &[u8], ddict: &DDict<'_> ) -> SafeResult

Fully decompress the given frame using a dictionary.

Dictionary must be identical to the one used during compression.

Wraps the ZSTD_decompress_usingDDict() function.

source

pub fn init(&mut self) -> SafeResult

Initializes an existing DStream for decompression.

This is equivalent to calling:

  • reset(SessionOnly)
  • disable_dictionary()

Wraps the ZSTD_initCStream() function.

source

pub fn reset(&mut self, reset: ResetDirective) -> SafeResult

Resets the state of the context.

Depending on the reset mode, it can reset the session, the parameters, or both.

Wraps the ZSTD_DCtx_reset() function.

source

pub fn load_dictionary(&mut self, dict: &[u8]) -> SafeResult

Loads a dictionary.

This will let this context decompress frames that were compressed using this 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 DDict first, then loads that.

The dictionary will apply to all future frames, until a new dictionary is set.

source

pub fn disable_dictionary(&mut self) -> SafeResult

Return to “no-dictionary” mode.

This will disable any dictionary/prefix previously registered for future frames.

source

pub fn ref_ddict<'b>(&mut self, ddict: &DDict<'b>) -> SafeResultwhere 'b: 'a,

References a dictionary.

This will let this context decompress frames compressed with the same dictionary.

It will apply to all frames decompressed by this context (until a new dictionary is set).

Wraps the ZSTD_DCtx_refDDict() function.

source

pub fn ref_prefix<'b>(&mut self, prefix: &'b [u8]) -> SafeResultwhere 'b: 'a,

Use some prefix as single-use dictionary for the next frame.

Just like a dictionary, this only works if compression was done with the same prefix.

But unlike a dictionary, this only applies to the next frame.

Wraps the ZSTD_DCtx_refPrefix() function.

source

pub fn set_parameter(&mut self, param: DParameter) -> SafeResult

Sets a decompression parameter.

source

pub fn decompress_stream<C: WriteBuf + ?Sized>( &mut self, output: &mut OutBuffer<'_, C>, input: &mut InBuffer<'_> ) -> SafeResult

Performs a step of a streaming decompression operation.

This will read some data from input and/or write some data to output.

Returns
  • Ok(0) if the current frame just finished decompressing successfully.
  • Ok(hint) with a hint for the “ideal” amount of input data to provide in the next call. Can be safely ignored.

Wraps the ZSTD_decompressStream() function.

source

pub fn in_size() -> usize

Wraps the ZSTD_DStreamInSize() function.

Returns a hint for the recommended size of the input buffer for decompression.

source

pub fn out_size() -> usize

Wraps the ZSTD_DStreamOutSize() function.

Returns a hint for the recommended size of the output buffer for decompression.

source

pub fn sizeof(&self) -> usize

Wraps the ZSTD_sizeof_DCtx() function.

Trait Implementations§

source§

impl Default for DCtx<'_>

source§

fn default() -> Self

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

impl Drop for DCtx<'_>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl Send for DCtx<'_>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for DCtx<'a>

§

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

§

impl<'a> Unpin for DCtx<'a>

§

impl<'a> UnwindSafe for DCtx<'a>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.