pub struct GzipStreamEncoder<W: Write> { /* private fields */ }Expand description
Streaming GZIP encoder that implements Write.
Maintains a single GZIP stream with a persistent Deflater and
running CRC-32. Flush methods (sync_flush, full_flush,
partial_flush) emit DEFLATE blocks within the same stream.
Important: you must call finish to
write the GZIP trailer. Dropping the encoder without calling finish
will produce an incomplete GZIP stream.
Implementations§
Source§impl<W: Write> GzipStreamEncoder<W>
impl<W: Write> GzipStreamEncoder<W>
Sourcepub fn new(writer: W, level: u8) -> Self
pub fn new(writer: W, level: u8) -> Self
Create a new streaming GZIP 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.
A sync flush emits a compressed block followed by an empty stored
block (0x00 0x00 0xFF 0xFF), which byte-aligns the stream and
allows a decoder to decode all data fed so far.
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.
After a full flush the compressor state is reset so subsequent data can be decompressed independently (given knowledge of the block boundary).
Sourcepub fn partial_flush(&mut self) -> Result<()>
pub fn partial_flush(&mut self) -> Result<()>
Partial flush: emit a compressed block without the sync marker.
The block is flushed to a byte boundary but no empty stored block is appended. This produces slightly smaller output than sync flush but the decoder cannot determine a safe decompression boundary.
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 GzipStreamEncoder<W>
impl<W: Write> Write for GzipStreamEncoder<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)