pub struct ZlibEncoder<W: Write> { /* private fields */ }
Expand description
A Zlib encoder powered by the Zopfli algorithm, that compresses data using
a DeflateEncoder
. Most users will find using compress
easier and more performant.
The caveats about short writes in DeflateEncoder
s carry over to ZlibEncoder
s:
for best performance and compression, it is best to avoid them. One way to ensure
this is to use the new_buffered
method.
Implementations§
Source§impl<W: Write> ZlibEncoder<W>
impl<W: Write> ZlibEncoder<W>
Sourcepub fn new(options: Options, btype: BlockType, sink: W) -> Result<Self, Error>
pub fn new(options: Options, btype: BlockType, sink: W) -> Result<Self, Error>
Creates a new Zlib encoder that will operate according to the specified options.
Sourcepub fn new_buffered(
options: Options,
btype: BlockType,
sink: W,
) -> Result<BufWriter<Self>, Error>
pub fn new_buffered( options: Options, btype: BlockType, sink: W, ) -> Result<BufWriter<Self>, Error>
Creates a new Zlib encoder that operates according to the specified options and is wrapped with a buffer to guarantee that data is compressed in large chunks, which is necessary for decent performance and good compression ratio.
Sourcepub fn finish(self) -> Result<W, Error>
pub fn finish(self) -> Result<W, Error>
Encodes any pending chunks of data and writes them to the sink, consuming the encoder and returning the wrapped sink. The sink will have received a complete Zlib stream when this method returns.
The encoder is automatically finish
ed when
dropped, but explicitly finishing it with this method allows
handling I/O errors.
Trait Implementations§
Source§impl<W: Write> Drop for ZlibEncoder<W>
impl<W: Write> Drop for ZlibEncoder<W>
Source§impl<W: Write> Write for ZlibEncoder<W>
impl<W: Write> Write for ZlibEncoder<W>
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§impl<W: Write> Write for ZlibEncoder<W>
impl<W: Write> Write for ZlibEncoder<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
)