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: usizeLength of the xz dictionary, or 0.
zstd_window_limit: usizeLargest zstd window, in bytes.
inflate: Option<DecompressorOxide>deflate only.xz: Option<XzDecoder<'a>>xz only.zstd: Option<FrameDecoder>zstd only.memory: PhantomData<&'a mut [u8]>Implementations§
§impl Decompressors<'_>
impl Decompressors<'_>
pub const fn new() -> Self
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.
pub fn enable_deflate(&mut self) -> &mut Self
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.
pub fn enable_lz4(&mut self) -> &mut Self
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.
pub fn enable_lzo(&mut self) -> &mut Self
lzo only.Enables LZO1X.
It doesn’t need working memory.
pub fn enable_zlib(&mut self) -> &mut Self
Available on crate feature deflate only.
pub fn enable_zlib(&mut self) -> &mut Self
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.
pub fn enable_zstd(&mut self) -> &mut Self
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>
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
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
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
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>
pub const fn xz_dictionary_len(&self) -> Option<usize>
Returns the length of the xz dictionary.
Returns None if xz isn’t enabled.