Struct ZlibEncoder

struct ZlibEncoder<R> { ... }

A ZLIB encoder, or compressor.

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

Examples

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

// Use a buffered file to compress contents into a Vec<u8>

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

Implementations

impl<R> ZlibEncoder<R>

fn reset(self: &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.

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

Acquires a reference to the underlying reader

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

Acquires a mutable reference to the underlying stream

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

fn into_inner(self: Self) -> R

Consumes this encoder, returning the underlying reader.

fn total_in(self: &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: &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: BufRead> 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.

impl<R> Freeze for ZlibEncoder<R>

impl<R> RefUnwindSafe for ZlibEncoder<R>

impl<R> Send for ZlibEncoder<R>

impl<R> Sync for ZlibEncoder<R>

impl<R> Unpin for ZlibEncoder<R>

impl<R> UnsafeUnpin for ZlibEncoder<R>

impl<R> UnwindSafe for ZlibEncoder<R>

impl<R: $crate::fmt::Debug> Debug for ZlibEncoder<R>

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

impl<R: BufRead + Write> Write for ZlibEncoder<R>

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

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

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

impl<T> Any for ZlibEncoder<R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for ZlibEncoder<R>

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

impl<T> BorrowMut for ZlibEncoder<R>

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

impl<T> From for ZlibEncoder<R>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for ZlibEncoder<R>

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 ZlibEncoder<R>

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

impl<T, U> TryInto for ZlibEncoder<R>

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