pub struct CompressContext { /* private fields */ }Expand description
Reusable compression context that amortizes hash table and buffer allocations.
Holds internal state (hash tables, output buffer, block encoder workspace) across calls. Useful when compressing many small inputs in a loop.
let mut ctx = zrip::CompressContext::new(1).unwrap();
for i in 0..10 {
let data = format!("message {i}").repeat(100);
let compressed = ctx.compress(data.as_bytes()).unwrap();
assert!(compressed.len() < data.len());
}Implementations§
Source§impl CompressContext
impl CompressContext
Sourcepub fn new(level: i32) -> Result<Self, CompressError>
pub fn new(level: i32) -> Result<Self, CompressError>
Creates a new context for the given compression level (-7..=4).
Sourcepub fn with_dict(level: i32, dict: Dictionary) -> Result<Self, CompressError>
pub fn with_dict(level: i32, dict: Dictionary) -> Result<Self, CompressError>
Creates a new context with a pre-loaded dictionary.
Sourcepub fn compress(&mut self, input: &[u8]) -> Result<Cow<'_, [u8]>, CompressError>
pub fn compress(&mut self, input: &[u8]) -> Result<Cow<'_, [u8]>, CompressError>
Compresses input using the context’s level and optional dictionary.
Sourcepub fn compress_with_dict(
&mut self,
input: &[u8],
dict: &Dictionary,
) -> Result<Cow<'_, [u8]>, CompressError>
pub fn compress_with_dict( &mut self, input: &[u8], dict: &Dictionary, ) -> Result<Cow<'_, [u8]>, CompressError>
Compresses input using an ad-hoc dictionary (overrides the stored one).
Auto Trait Implementations§
impl Freeze for CompressContext
impl RefUnwindSafe for CompressContext
impl Send for CompressContext
impl Sync for CompressContext
impl Unpin for CompressContext
impl UnsafeUnpin for CompressContext
impl UnwindSafe for CompressContext
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