pub struct Encoder(/* private fields */);
Expand description
Stateful context for compression.
See the crate level compression section for detailed usage.
Implementations§
source§impl Encoder
impl Encoder
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new deflate encoder. Note that creating an encoder with this method allocates a large (200-300k) chunk of data on the stack and is likely to cause an overflow if not carefully managed. See the boxed() constructor for a safer method that allocates on the heap.
sourcepub fn set_format(&mut self, format: Format)
pub fn set_format(&mut self, format: Format)
Sets the format of the output bitstream for the next usage of the encoder.
sourcepub fn set_level(&mut self, level: CompressionLevel)
pub fn set_level(&mut self, level: CompressionLevel)
Sets the compression level for the next usage of the encoder.
sourcepub fn set_strategy(&mut self, strategy: CompressionStrategy)
pub fn set_strategy(&mut self, strategy: CompressionStrategy)
Sets the compression strategy for the next usage of the encoder.
sourcepub fn stream<'a, W: Write>(
&'a mut self,
writer: &'a mut W,
) -> EncoderStream<'a, impl Sink + 'a> ⓘ
pub fn stream<'a, W: Write>( &'a mut self, writer: &'a mut W, ) -> EncoderStream<'a, impl Sink + 'a> ⓘ
Creates an encoder stream that will write into the specified writer.
sourcepub fn stream_into_vec<'a>(
&'a mut self,
vec: &'a mut Vec<u8>,
) -> EncoderStream<'a, impl Sink + 'a> ⓘ
pub fn stream_into_vec<'a>( &'a mut self, vec: &'a mut Vec<u8>, ) -> EncoderStream<'a, impl Sink + 'a> ⓘ
Creates an encoder stream that will write into the specified vector. The resulting stream will not clear the vector but will instead append the compressed data.
sourcepub fn stream_into_buf<'a>(
&'a mut self,
buf: &'a mut [u8],
) -> EncoderStream<'a, impl Sink + 'a> ⓘ
pub fn stream_into_buf<'a>( &'a mut self, buf: &'a mut [u8], ) -> EncoderStream<'a, impl Sink + 'a> ⓘ
Creates an encoder stream that will write into the specified buffer. The stream will generate an overflow error if the buffer is not large enough to contain the compressed data.