[][src]Struct zstd::stream::write::Encoder

pub struct Encoder<W: Write> { /* fields omitted */ }

An encoder that compress and forward data to another writer.

This allows to compress a stream of data (good for files or heavy network stream).

Don't forget to call finish() before dropping it!

Note: The zstd library has its own internal input buffer (~128kb).

Methods

impl<W: Write> Encoder<W>[src]

pub fn new(writer: W, level: i32) -> Result<Self>[src]

Creates a new encoder.

level: compression level (1-21).

A level of 0 uses zstd's default (currently 3).

pub fn with_dictionary(writer: W, level: i32, dictionary: &[u8]) -> Result<Self>[src]

Creates a new encoder, using an existing dictionary.

(Provides better compression ratio for small files, but requires the dictionary to be present during decompression.)

A level of 0 uses zstd's default (currently 3).

pub fn with_prepared_dictionary(
    writer: W,
    dictionary: &EncoderDictionary
) -> Result<Self>
[src]

Creates a new encoder, using an existing prepared EncoderDictionary.

(Provides better compression ratio for small files, but requires the dictionary to be present during decompression.)

Important traits for AutoFinishEncoder<W>
pub fn auto_finish(self) -> AutoFinishEncoder<W>[src]

Returns a wrapper around self that will finish the stream on drop.

Panic

Panics on drop if an error happens when finishing the stream.

Important traits for AutoFinishEncoder<W>
pub fn on_finish<F: 'static + FnMut(Result<W>)>(
    self,
    f: F
) -> AutoFinishEncoder<W>
[src]

Returns an encoder that will finish the stream on drop.

Calls the given callback with the result from finish().

pub fn get_ref(&self) -> &W[src]

Acquires a reference to the underlying writer.

pub fn get_mut(&mut self) -> &mut W[src]

Acquires a mutable reference to the underlying writer.

Note that mutation of the writer may result in surprising results if this encoder is continued to be used.

pub fn finish(self) -> Result<W>[src]

Required: Finishes the stream.

You need to finish the stream when you're done writing, either with this method or with try_finish(self).

This returns the inner writer in case you need it.

To get back self in case an error happened, use try_finish.

Note: If you don't want (or can't) call finish() manually after writing your data, consider using auto_finish() to get an AutoFinishEncoder.

pub fn try_finish(self) -> Result<W, (Self, Error)>[src]

Required: Attempts to finish the stream.

You need to finish the stream when you're done writing, either with this method or with finish(self).

This returns the inner writer if the finish was successful, or the object plus an error if it wasn't.

write on this object will panic after try_finish has been called, even if it fails.

pub fn do_finish(&mut self) -> Result<()>[src]

Attemps to finish the stream.

You need to finish the stream when you're done writing, either with this method or with finish(self).

pub fn recommended_input_size() -> usize[src]

Return a recommendation for the size of data to write at once.

pub fn include_checksum(&mut self, include_checksum: bool) -> Result<()>[src]

Controls whether zstd should include a content checksum at the end of each frame.

pub fn multithread(&mut self, n_workers: u32) -> Result<()>[src]

Enables multithreaded compression

  • If n_workers == 0 (default), then multithreaded will be disabled.
  • If n_workers >= 1, then compression will be done in separate threads. So even n_workers = 1 may increase performance by separating IO and compression.

Trait Implementations

impl<W: Write> Write for Encoder<W>[src]

Auto Trait Implementations

impl<W> Send for Encoder<W> where
    W: Send

impl<W> !Sync for Encoder<W>

impl<W> Unpin for Encoder<W> where
    W: Unpin

impl<W> UnwindSafe for Encoder<W> where
    W: UnwindSafe

impl<W> RefUnwindSafe for Encoder<W> where
    W: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]