pub struct ZlibStreamEncoder<W: Write> { /* private fields */ }Expand description
Streaming Zlib encoder that implements Write.
Maintains a single Zlib stream with a persistent Deflater and
running Adler-32. Flush methods (sync_flush, full_flush,
partial_flush) emit DEFLATE blocks within the same stream.
Important: you must call finish to
write the Adler-32 trailer. Dropping the encoder without calling finish
will produce an incomplete Zlib stream.
Implementations§
Source§impl<W: Write> ZlibStreamEncoder<W>
impl<W: Write> ZlibStreamEncoder<W>
Sourcepub fn new(writer: W, level: u8) -> Self
pub fn new(writer: W, level: u8) -> Self
Create a new streaming Zlib encoder wrapping writer.
The level parameter controls the DEFLATE compression level (0-9).
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 flushed via sync_flush.
Sourcepub fn sync_flush(&mut self) -> Result<()>
pub fn sync_flush(&mut self) -> Result<()>
Drain the internal buffer through the deflater using a sync flush.
Sourcepub fn full_flush(&mut self) -> Result<()>
pub fn full_flush(&mut self) -> Result<()>
Full flush: same as sync flush, then reset the LZ77 state.
Sourcepub fn partial_flush(&mut self) -> Result<()>
pub fn partial_flush(&mut self) -> Result<()>
Partial flush: emit a compressed block without the sync marker.
Sourcepub fn finish(self) -> Result<W>
pub fn finish(self) -> Result<W>
Finish compression and return the inner writer.
This must be called to write the Adler-32 trailer.
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 ZlibStreamEncoder<W>
impl<W: Write> Write for ZlibStreamEncoder<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)