Skip to main content

Decompressor

Struct Decompressor 

Source
pub struct Decompressor<'a> {
    context: DCtx<'a>,
}
Expand description

Allows to decompress independently multiple blocks of data.

This reduces memory usage compared to calling decompress multiple times.

Fields§

§context: DCtx<'a>

Implementations§

Source§

impl Decompressor<'static>

Source

pub fn new() -> Result<Self>

Creates a new zstd decompressor.

Source

pub fn with_dictionary(dictionary: &[u8]) -> Result<Self>

Creates a new zstd decompressor, using the given dictionary.

Source§

impl<'a> Decompressor<'a>

Source

pub fn with_prepared_dictionary<'b>( dictionary: &'a DecoderDictionary<'b>, ) -> Result<Self>
where 'b: 'a,

Creates a new decompressor using an existing DecoderDictionary.

Note that using a dictionary means that compression will need to use the same dictionary.

Source

pub fn set_dictionary(&mut self, dictionary: &[u8]) -> Result<()>

Changes the dictionary used by this decompressor.

Will affect future compression jobs.

Note that using a dictionary means that compression will need to use the same dictionary.

Source

pub fn set_prepared_dictionary<'b>( &mut self, dictionary: &'a DecoderDictionary<'b>, ) -> Result<()>
where 'b: 'a,

Changes the dictionary used by this decompressor.

Note that using a dictionary means that compression will need to use the same dictionary.

Source

pub fn decompress_to_buffer<C: WriteBuf + ?Sized>( &mut self, source: &[u8], destination: &mut C, ) -> Result<usize>

Deompress 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). crate::decompressed_size() says how big the result will be, when the frame records it - there is no need to keep the size alongside the data yourself. For a Vec it is the capacity that bounds the output, so reserve what you need rather than resize.

Source

pub fn decompress(&mut self, data: &[u8], capacity: usize) -> Result<Vec<u8>>

Decompress a block of data, and return the result in a Vec<u8>.

The decompressed data should be at most capacity bytes, or an error will be returned.

Source

pub fn set_parameter(&mut self, parameter: DParameter) -> Result<()>

Sets a decompression parameter for this decompressor.

Source

pub fn window_log_max(&mut self, log_distance: u32) -> Result<()>

Sets the maximum back-reference distance.

The actual maximum distance is going to be 2^log_distance.

This will need to at least match the value set when compressing.

Source

pub fn upper_bound(data: &[u8]) -> Option<usize>

Get an upper bound on the decompressed size of data, if available

This can be used to pre-allocate enough capacity for decompress_to_buffer and is used by decompress to ensure that it does not over-allocate if you supply a large capacity.

Returns None if the size cannot be determined, or does not fit a usize. That happens when the frame does not record its decompressed size - which is normal for anything a streaming compressor produced without being told the length up front.

With the experimental feature this sums every frame in data. Without it, the answer is limited to a single frame, since the function that adds them up is part of zstd’s experimental API.

Trait Implementations§

Source§

impl<'a> Default for Decompressor<'a>

Source§

fn default() -> Decompressor<'a>

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

Auto Trait Implementations§

§

impl<'a> Freeze for Decompressor<'a>

§

impl<'a> RefUnwindSafe for Decompressor<'a>

§

impl<'a> Send for Decompressor<'a>

§

impl<'a> Sync for Decompressor<'a>

§

impl<'a> Unpin for Decompressor<'a>

§

impl<'a> UnsafeUnpin for Decompressor<'a>

§

impl<'a> UnwindSafe for Decompressor<'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.