Struct ZlibEncoder

pub struct ZlibEncoder<R> { /* private fields */ }

A ZLIB encoder, or compressor.

This structure implements a Read interface. When read from, it reads uncompressed data from the underlying Read and provides the compressed data.

Examples

use std::io::prelude::*;
use flate2::Compression;
use flate2::read::ZlibEncoder;
use std::fs::File;

// Open example file and compress the contents using Read interface

# fn open_hello_world() -> std::io::Result<Vec<u8>> {
let f = File::open("examples/hello_world.txt")?;
let mut z = ZlibEncoder::new(f, Compression::fast());
let mut buffer = Vec::new();
z.read_to_end(&mut buffer)?;
# Ok(buffer)
# }

Implementations

impl<R> ZlibEncoder<R>

fn reset(&mut self, r: R) -> R

Resets the state of this encoder entirely, swapping out the input stream for another.

This function will reset the internal state of this encoder and replace the input stream with the one provided, returning the previous input stream. Future data read from this encoder will be the compressed version of r's data.

Note that there may be currently buffered data when this function is called, and in that case the buffered data is discarded.

fn get_ref(&self) -> &R

Acquires a reference to the underlying stream

fn get_mut(&mut self) -> &mut R

Acquires a mutable reference to the underlying stream

The underlying reader may be mutated as long as its unread input and current position are preserved for subsequent reads by this encoder.

To process a new stream, wait for this encoder to reach EOF and use reset; replacing the reader directly does not reset it.

fn into_inner(self) -> R

Consumes this encoder, returning the underlying reader.

Note that there may be buffered bytes which are not re-acquired as part of this transition. It's recommended to only call this function after EOF has been reached.

fn total_in(&self) -> u64

Returns the number of bytes that have been read into this compressor.

Note that not all bytes read from the underlying object may be accounted for, there may still be some active buffering.

fn total_out(&self) -> u64

Returns the number of bytes that the compressor has produced.

Note that not all bytes may have been read yet, some may still be buffered.

impl<R: Read> ZlibEncoder<R>

fn new(r: R, level: Compression) -> ZlibEncoder<R>

Creates a new encoder which will read uncompressed data from the given stream and emit the compressed stream.

fn new_with_compress(r: R, compression: Compress) -> ZlibEncoder<R>

Creates a new encoder with the given compression settings which will read uncompressed data from the given stream r and emit the compressed stream.

Trait Implementations

impl<R: Debug> Debug for ZlibEncoder<R>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<R: Read> Read for ZlibEncoder<R>

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

impl<W: Read + Write> Write for ZlibEncoder<W>

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

Auto Trait Implementations

impl<R> !UnwindSafe for ZlibEncoder<R>

impl<R> Freeze for ZlibEncoder<R> where ZlibEncoder<BufReader<R>>: Freeze,

impl<R> RefUnwindSafe for ZlibEncoder<R> where ZlibEncoder<BufReader<R>>: RefUnwindSafe,

impl<R> Send for ZlibEncoder<R> where ZlibEncoder<BufReader<R>>: Send,

impl<R> Sync for ZlibEncoder<R> where ZlibEncoder<BufReader<R>>: Sync,

impl<R> Unpin for ZlibEncoder<R> where ZlibEncoder<BufReader<R>>: Unpin,

impl<R> UnsafeUnpin for ZlibEncoder<R> where ZlibEncoder<BufReader<R>>: UnsafeUnpin,

Blanket Implementations

impl<T> Any for ZlibEncoder<R> where T: 'static + ?Sized,

impl<T> Borrow<T> for ZlibEncoder<R> where T: ?Sized,

impl<T> BorrowMut<T> for ZlibEncoder<R> where T: ?Sized,

impl<T> From<T> for ZlibEncoder<R>

impl<T, U> Into<U> for ZlibEncoder<R> where U: From<T>,

impl<T, U> TryFrom<U> for ZlibEncoder<R> where U: Into<T>,

impl<T, U> TryInto<U> for ZlibEncoder<R> where U: TryFrom<T>,