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 Read and provides the compressed data.

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 = Vec::new();
    let bytestring = b"hello world";
    let mut gz = GzEncoder::new(&bytestring[..], Compression::fast());
    gz.read_to_end(&mut ret_vec)?;
    Ok(ret_vec)
}

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.

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

fn into_inner(self) -> R

Returns the underlying stream, consuming this encoder

impl<R: Read> 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: Debug> Debug for GzEncoder<R>

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

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

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

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

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

Auto Trait Implementations

impl<R> !UnwindSafe for GzEncoder<R>

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

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

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

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

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

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

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

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

fn from(t: T) -> T

Returns the argument unchanged.

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

fn into(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<U> for GzEncoder<R> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

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