pub struct DecompressContext { /* private fields */ }Expand description
Reusable decompression context that amortizes buffer allocations.
Holds internal buffers (output, Huffman/FSE workspace) across calls. Useful when decompressing many small frames in a loop.
let data = b"repeated decompression".repeat(100);
let compressed = zrip::compress(&data, 1).unwrap();
let mut ctx = zrip::DecompressContext::new();
for _ in 0..10 {
let output = ctx.decompress(&compressed).unwrap();
assert_eq!(&*output, &data[..]);
}Implementations§
Source§impl DecompressContext
impl DecompressContext
Sourcepub fn with_dict(dict: Dictionary) -> Self
pub fn with_dict(dict: Dictionary) -> Self
Creates a new context with a pre-loaded dictionary.
Sourcepub fn decompress(
&mut self,
input: &[u8],
) -> Result<Cow<'_, [u8]>, DecompressError>
pub fn decompress( &mut self, input: &[u8], ) -> Result<Cow<'_, [u8]>, DecompressError>
Decompresses input using DEFAULT_DECOMPRESS_LIMIT.
Sourcepub fn decompress_with_limit(
&mut self,
input: &[u8],
max_output: usize,
) -> Result<Cow<'_, [u8]>, DecompressError>
pub fn decompress_with_limit( &mut self, input: &[u8], max_output: usize, ) -> Result<Cow<'_, [u8]>, DecompressError>
Decompresses input with an explicit output size limit.
Returns DecompressError::OutputTooSmall if the decompressed output
would exceed max_output bytes.
Sourcepub fn decompress_after_magic_with_limit(
&mut self,
input: &[u8],
max_output: usize,
) -> Result<Cow<'_, [u8]>, DecompressError>
pub fn decompress_after_magic_with_limit( &mut self, input: &[u8], max_output: usize, ) -> Result<Cow<'_, [u8]>, DecompressError>
Decompresses one zstd frame whose 4-byte magic number is stored out of band.
OpenZL stores zstd payloads this way inside transform streams.
Sourcepub fn decompress_after_magic_into(
&mut self,
input: &[u8],
output: &mut Vec<u8>,
max_output: usize,
) -> Result<usize, DecompressError>
pub fn decompress_after_magic_into( &mut self, input: &[u8], output: &mut Vec<u8>, max_output: usize, ) -> Result<usize, DecompressError>
Decompresses one zstd frame without its magic number into output.
Appends to output and returns the number of bytes written.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DecompressContext
impl RefUnwindSafe for DecompressContext
impl Send for DecompressContext
impl Sync for DecompressContext
impl Unpin for DecompressContext
impl UnsafeUnpin for DecompressContext
impl UnwindSafe for DecompressContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more