Struct GzEncoder

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

A gzip streaming encoder

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 std::io;
use flate2::Compression;
use flate2::bufread::GzEncoder;
use std::fs::File;
use std::io::BufReader;

// Opens sample file, compresses the contents and returns a Vector or error
// File wrapped in a BufReader implements BufRead

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

Implementations

impl<R> GzEncoder<R>

fn get_ref(&self) -> &R

Acquires a reference to the underlying reader.

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

Acquires a mutable reference to the underlying reader.

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 create a new encoder; replacing the reader directly does not reset it.

fn into_inner(self) -> R

Returns the underlying stream, consuming this encoder

impl<R: BufRead> GzEncoder<R>

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

Creates a new encoder which will use the given compression level.

The encoder is not configured specially for the emitted header. For header configuration, see the GzBuilder type.

The data read from the stream r will be compressed and available through the returned reader.

Trait Implementations

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

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

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

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

impl<R: Debug> Debug for GzEncoder<R>

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

Auto Trait Implementations

impl<R> !UnwindSafe for GzEncoder<R>

impl<R> Freeze for GzEncoder<R> where DeflateEncoder<CrcReader<R>>: Freeze,

impl<R> RefUnwindSafe for GzEncoder<R> where DeflateEncoder<CrcReader<R>>: RefUnwindSafe,

impl<R> Send for GzEncoder<R> where DeflateEncoder<CrcReader<R>>: Send,

impl<R> Sync for GzEncoder<R> where DeflateEncoder<CrcReader<R>>: Sync,

impl<R> Unpin for GzEncoder<R> where DeflateEncoder<CrcReader<R>>: Unpin,

impl<R> UnsafeUnpin for GzEncoder<R> where DeflateEncoder<CrcReader<R>>: UnsafeUnpin,

Blanket Implementations

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

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

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

impl<T> From<T> for GzEncoder<R>

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

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

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