pub struct StreamingEncoder<W: Write, M: Matcher = MatchGeneratorDriver> { /* private fields */ }Expand description
Incremental frame encoder that implements Write.
Data can be provided with multiple write() calls. Full blocks are compressed
automatically, flush() emits the currently buffered partial block as non-last,
and finish() closes the frame and returns the wrapped writer.
Implementations§
Source§impl<W: Write> StreamingEncoder<W, MatchGeneratorDriver>
impl<W: Write> StreamingEncoder<W, MatchGeneratorDriver>
Sourcepub fn new(drain: W, compression_level: CompressionLevel) -> Self
pub fn new(drain: W, compression_level: CompressionLevel) -> Self
Creates a streaming encoder backed by the default match generator.
The encoder writes compressed bytes into drain and applies compression_level
to all subsequently written blocks.
Source§impl<W: Write, M: Matcher> StreamingEncoder<W, M>
impl<W: Write, M: Matcher> StreamingEncoder<W, M>
Sourcepub fn new_with_matcher(
matcher: M,
drain: W,
compression_level: CompressionLevel,
) -> Self
pub fn new_with_matcher( matcher: M, drain: W, compression_level: CompressionLevel, ) -> Self
Creates a streaming encoder with an explicitly provided matcher implementation.
This constructor is primarily intended for tests and advanced callers that need custom match-window behavior.
Sourcepub fn set_pledged_content_size(&mut self, size: u64) -> Result<(), Error>
pub fn set_pledged_content_size(&mut self, size: u64) -> Result<(), Error>
Pledge the total uncompressed content size for this frame.
When set, the frame header will include a Frame_Content_Size field.
This enables decoders to pre-allocate output buffers.
Must be called before the first write call;
calling it after the frame header has already been emitted returns an
error.
Sourcepub fn get_ref(&self) -> &W
pub fn get_ref(&self) -> &W
Returns an immutable reference to the wrapped output drain.
The drain remains available for the encoder lifetime; finish
consumes the encoder and returns ownership of the drain.
Sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Returns a mutable reference to the wrapped output drain.
It is inadvisable to directly write to the underlying writer, as doing so would corrupt the zstd frame being assembled by the encoder.
The drain remains available for the encoder lifetime; finish
consumes the encoder and returns ownership of the drain.
Trait Implementations§
Source§impl<W: Write, M: Matcher> Write for StreamingEncoder<W, M>
impl<W: Write, M: Matcher> Write for StreamingEncoder<W, M>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
fn write(&mut self, buf: &[u8]) -> Result<usize, Error>
Source§fn flush(&mut self) -> Result<(), Error>
fn flush(&mut self) -> Result<(), Error>
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)