pub struct FrameEncoder<W: Write> { /* private fields */ }Expand description
Streaming zstd compressor implementing Write.
Buffers input until a full block (128 KiB) is ready, then compresses
and writes it to the underlying writer. Call finish
to flush the final block, write the content checksum, and recover the
writer.
Internal buffers (hash tables, sequence scratch, block encoder workspace)
are allocated once and reused across blocks. To reuse them across
multiple frames, call reset instead of finish:
use std::io::Write;
let mut encoder = zrip::FrameEncoder::new(Vec::new(), 1).unwrap();
encoder.write_all(b"first frame").unwrap();
let first = encoder.reset(Vec::new()).unwrap(); // reuses buffers
encoder.write_all(b"second frame").unwrap();
let second = encoder.finish().unwrap();Implementations§
Source§impl<W: Write> FrameEncoder<W>
impl<W: Write> FrameEncoder<W>
Sourcepub fn new(writer: W, level: i32) -> Result<Self, CompressError>
pub fn new(writer: W, level: i32) -> Result<Self, CompressError>
Creates a new streaming encoder at the given level (-7..=4).
Sourcepub fn with_dict(
writer: W,
level: i32,
dict: Dictionary,
) -> Result<Self, CompressError>
pub fn with_dict( writer: W, level: i32, dict: Dictionary, ) -> Result<Self, CompressError>
Creates a new streaming encoder with a dictionary at the given level (-7..=4).
Sourcepub fn finish(self) -> Result<W, Error>
pub fn finish(self) -> Result<W, Error>
Flushes remaining data, writes the content checksum, and returns the inner writer.
Sourcepub fn reset(&mut self, new_writer: W) -> Result<W, Error>
pub fn reset(&mut self, new_writer: W) -> Result<W, Error>
Finishes the current frame and installs new_writer for the next one.
Returns the previous writer containing the completed frame. All internal buffers (hash tables, workspace, block scratch) stay allocated and are reused for the next frame.
Trait Implementations§
Source§impl<W: Write> Write for FrameEncoder<W>
impl<W: Write> Write for FrameEncoder<W>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)