pub struct DeflateEncoder<W: Write> { /* private fields */ }
Expand description
A DEFLATE encoder powered by the Zopfli algorithm that compresses data written
to it to the specified sink. Most users will find using compress
easier and more performant.
The data will be compressed as soon as possible, without trying to fill a
backreference window. As a consequence, frequent short writes may cause more
DEFLATE blocks to be emitted with less optimal Huffman trees, which can hurt
compression and runtime. If they are a concern, short writes can be conveniently
dealt with by wrapping this encoder with a BufWriter
, as done
by the new_buffered
method. An adequate write size
would be >32 KiB, which allows the second complete chunk to leverage a full-sized
backreference window.
Implementations§
Source§impl<W: Write> DeflateEncoder<W>
impl<W: Write> DeflateEncoder<W>
Sourcepub fn new(options: Options, btype: BlockType, sink: W) -> Self
pub fn new(options: Options, btype: BlockType, sink: W) -> Self
Creates a new Zopfli DEFLATE encoder that will operate according to the specified options.
Sourcepub fn new_buffered(
options: Options,
btype: BlockType,
sink: W,
) -> BufWriter<Self>
pub fn new_buffered( options: Options, btype: BlockType, sink: W, ) -> BufWriter<Self>
Creates a new Zopfli DEFLATE 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 DEFLATE 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 DeflateEncoder<W>
impl<W: Write> Drop for DeflateEncoder<W>
Source§impl<W: Write> Write for DeflateEncoder<W>
impl<W: Write> Write for DeflateEncoder<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 DeflateEncoder<W>
impl<W: Write> Write for DeflateEncoder<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
)