Struct DeflateEncoder

struct DeflateEncoder<W: Write> { ... }

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

impl<W: Write> DeflateEncoder<W>

fn new(options: Options, btype: BlockType, sink: W) -> Self

Creates a new Zopfli DEFLATE encoder that will operate according to the specified options.

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.

fn finish(self: 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 finished when dropped, but explicitly finishing it with this method allows handling I/O errors.

fn get_ref(self: &Self) -> &W

Gets a reference to the underlying writer.

fn get_mut(self: &mut Self) -> &mut W

Gets a mutable reference to the underlying writer.

Note that mutating the output/input state of the stream may corrupt this object, so care must be taken when using this method.

impl<T> Any for DeflateEncoder<W>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for DeflateEncoder<W>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for DeflateEncoder<W>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for DeflateEncoder<W>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for DeflateEncoder<W>

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for DeflateEncoder<W>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for DeflateEncoder<W>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>

impl<W> Freeze for DeflateEncoder<W>

impl<W> RefUnwindSafe for DeflateEncoder<W>

impl<W> Send for DeflateEncoder<W>

impl<W> Sync for DeflateEncoder<W>

impl<W> Unpin for DeflateEncoder<W>

impl<W> UnsafeUnpin for DeflateEncoder<W>

impl<W> UnwindSafe for DeflateEncoder<W>

impl<W: Write> Drop for DeflateEncoder<W>

fn drop(self: &mut Self)

impl<W: Write> Write for DeflateEncoder<W>

fn write(self: &mut Self, buf: &[u8]) -> Result<usize, Error>
fn flush(self: &mut Self) -> Result<(), Error>

impl<W: crate::io::Write> Write for DeflateEncoder<W>

fn write(self: &mut Self, _buf: &[u8]) -> Result<usize>
fn flush(self: &mut Self) -> Result<()>