Skip to main content

Decompressors

Struct Decompressors 

pub struct Decompressors<'a> {
    enabled: Algorithms,
    xz_dictionary_len: usize,
    zstd_window_limit: usize,
    inflate: Option<DecompressorOxide>,
    xz: Option<XzDecoder<'a>>,
    zstd: Option<FrameDecoder>,
    memory: PhantomData<&'a mut [u8]>,
}
Expand description

Algorithms that the caller allows, with their working memory.

Decompressors::new enables none. Each enable_ method needs the feature of its algorithm. 'a is the lifetime of memory that the caller lends, such as the xz dictionary.

use flashkit_compression::{Algorithm, DecompressError, Decompressors};

let mut decompressors = Decompressors::new();
decompressors.enable_lzo();
let mut out = [0; 16];
let len = decompressors.decompress(Algorithm::Lzo, b"\x16hello\x11\0\0", &mut out)?;
assert_eq!(&out[..len], b"hello");
assert_eq!(
    decompressors.decompress(Algorithm::Zstd, b"", &mut out),
    Err(DecompressError::NotEnabled {
        algorithm: Algorithm::Zstd
    })
);

Fields§

§enabled: Algorithms§xz_dictionary_len: usize

Length of the xz dictionary, or 0.

§zstd_window_limit: usize

Largest zstd window, in bytes.

§inflate: Option<DecompressorOxide>
Available on crate feature deflate only.
§xz: Option<XzDecoder<'a>>
Available on crate feature xz only.
§zstd: Option<FrameDecoder>
Available on crate feature zstd only.
§memory: PhantomData<&'a mut [u8]>

Implementations§

§

impl Decompressors<'_>

pub const fn new() -> Self

Creates a set without any algorithm.

pub fn enable_deflate(&mut self) -> &mut Self

Available on crate feature deflate only.

Enables raw deflate.

Deflate and zlib share a state of about 11 KiB, which is part of this value.

pub fn enable_lz4(&mut self) -> &mut Self

Available on crate feature lz4 only.

Enables LZ4 blocks.

They don’t need working memory.

pub fn enable_lzo(&mut self) -> &mut Self

Available on crate feature lzo only.

Enables LZO1X.

It doesn’t need working memory.

pub fn enable_zlib(&mut self) -> &mut Self

Available on crate feature deflate only.

Enables deflate in zlib streams.

See Self::enable_deflate for its state.

pub fn enable_zstd(&mut self) -> &mut Self

Available on crate feature zstd only.

Enables zstd.

On first use, it allocates a window of up to the limit of Self::limit_zstd_window and about 256 KiB of scratch memory.

pub fn decompress( &mut self, algorithm: Algorithm, input: &[u8], output: &mut [u8], ) -> Result<usize, DecompressError>

Decompresses the block input with algorithm into output.

Returns the length of the result.

§Errors

Returns DecompressError::NotEnabled if the algorithm isn’t enabled, or DecompressError::Invalid if the block is invalid or its result doesn’t fit into output.

pub const fn is_enabled(&self, algorithm: Algorithm) -> bool

Returns whether blocks with algorithm can be decompressed.

pub const fn limit_zstd_window(&mut self, len: usize) -> &mut Self

Limits the window that zstd allocates to len bytes.

Frames with a larger window fail to decompress. The default limit is 1 MiB.

pub const fn zstd_window_limit(&self) -> usize

Returns the largest window that zstd allocates, in bytes.

pub const fn xz_dictionary_len(&self) -> Option<usize>

Returns the length of the xz dictionary.

Returns None if xz isn’t enabled.

§

impl<'a> Decompressors<'a>

pub fn enable_xz(&mut self, dictionary: &'a mut [u8]) -> &mut Self

Available on crate feature xz only.

Enables xz with dictionary as its dictionary.

Streams with a larger dictionary fail to decompress. The decoder state of about 30 KiB is part of this value.

Trait Implementations§

§

impl Debug for Decompressors<'_>

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Default for Decompressors<'_>

§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for Decompressors<'a>

§

impl<'a> Freeze for Decompressors<'a>

§

impl<'a> RefUnwindSafe for Decompressors<'a>

§

impl<'a> Send for Decompressors<'a>

§

impl<'a> Sync for Decompressors<'a>

§

impl<'a> Unpin for Decompressors<'a>

§

impl<'a> UnsafeUnpin for Decompressors<'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 = !

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.