pub struct ZstdStreamEncoder<W: Write> { /* private fields */ }Expand description
Streaming Zstandard encoder that implements Write.
Data written to this encoder is buffered internally. When the internal
buffer reaches block_size bytes it is automatically flushed as a
complete Zstandard frame to the inner writer (truly incremental). Any
remaining data is flushed when finish is
called.
The output is a sequence of valid concatenated Zstandard frames and can be
decoded with decompress_multi_frame.
Important: you must call finish to
flush the final (possibly partial) block. Dropping the encoder without
calling finish will silently discard any buffered data.
Implementations§
Source§impl<W: Write> ZstdStreamEncoder<W>
impl<W: Write> ZstdStreamEncoder<W>
Sourcepub fn new(writer: W, level: i32) -> Self
pub fn new(writer: W, level: i32) -> Self
Create a new streaming encoder wrapping writer.
The level parameter controls the compression level passed to the
underlying ZstdEncoder. The encoder uses a default block size of
128 KiB; use with_block_size
to customise this.
Sourcepub fn with_dictionary(writer: W, level: i32, dict: Vec<u8>) -> Self
pub fn with_dictionary(writer: W, level: i32, dict: Vec<u8>) -> Self
Create a new streaming encoder with a pre-trained dictionary.
Dictionary-based compression improves ratios for small payloads that share common patterns.
Sourcepub fn with_block_size(self, block_size: usize) -> Self
pub fn with_block_size(self, block_size: usize) -> Self
Set the block size used for incremental flushing.
When the internal buffer reaches this many bytes it is automatically compressed and written to the inner writer as a Zstandard frame.
Sourcepub fn buffered_bytes(&self) -> usize
pub fn buffered_bytes(&self) -> usize
Returns the number of uncompressed bytes currently buffered.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Returns true if finish has already been called.
Trait Implementations§
Source§impl<W: Write> Write for ZstdStreamEncoder<W>
impl<W: Write> Write for ZstdStreamEncoder<W>
Source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Buffer buf and flush a frame to the inner writer whenever the
internal buffer reaches block_size.
Source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush any buffered data as a Zstandard frame to the inner writer.
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)