[][src]Struct flate2::bufread::GzEncoder

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

A gzip streaming encoder

This structure exposes a BufRead interface that will read uncompressed data from the underlying reader and expose the compressed version as a BufRead interface.

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)
}

Methods

impl<R: BufRead> GzEncoder<R>[src]

Important traits for GzEncoder<R>
pub fn new(r: R, level: Compression) -> GzEncoder<R>[src]

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.

impl<R> GzEncoder<R>[src]

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

Acquires a reference to the underlying reader.

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

Acquires a mutable reference to the underlying reader.

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

pub fn into_inner(self) -> R[src]

Returns the underlying stream, consuming this encoder

Trait Implementations

impl<R: Debug> Debug for GzEncoder<R>[src]

impl<R: BufRead> Read for GzEncoder<R>[src]

impl<R: BufRead + Write> Write for GzEncoder<R>[src]

Auto Trait Implementations

impl<R> Send for GzEncoder<R> where
    R: Send

impl<R> Unpin for GzEncoder<R> where
    R: Unpin

impl<R> Sync for GzEncoder<R> where
    R: Sync

impl<R> UnwindSafe for GzEncoder<R> where
    R: UnwindSafe

impl<R> RefUnwindSafe for GzEncoder<R> where
    R: 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> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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