Struct flate2::read::GzEncoder[][src]

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

A gzip streaming encoder

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

Examples

use std::io::prelude::*;
use std::io;
use flate2::Compression;
use flate2::read::GzEncoder;

// Return a vector containing the GZ compressed version of hello world

fn gzencode_hello_world() -> io::Result<Vec<u8>> {
    let mut ret_vec = [0;100];
    let bytestring = b"hello world";
    let mut gz = GzEncoder::new(&bytestring[..], Compression::fast());
    let count = gz.read(&mut ret_vec)?;
    Ok(ret_vec[0..count].to_vec())
}

Implementations

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

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

Notable traits for GzEncoder<R>

impl<R: Read> Read for GzEncoder<R>impl<R: Read + Write> Write for 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: Read> Read for GzEncoder<R>[src]

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

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<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.