Struct MultiGzDecoder

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

A gzip streaming decoder that decodes a gzip file that may have multiple members.

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

A gzip file consists of a series of members concatenated one after another. MultiGzDecoder decodes all members of a file and returns Ok(0) once the underlying reader does.

To handle members separately, see [GzDecoder] or read more in the introduction.

Examples

use std::io::prelude::*;
use std::io;
# use flate2::Compression;
# use flate2::write::GzEncoder;
use flate2::read::MultiGzDecoder;

# fn main() {
#    let mut e = GzEncoder::new(Vec::new(), Compression::default());
#    e.write_all(b"Hello World").unwrap();
#    let bytes = e.finish().unwrap();
#    println!("{}", decode_reader(bytes).unwrap());
# }
#
// Uncompresses a Gz Encoded vector of bytes and returns a string or error
// Here &[u8] implements Read

fn decode_reader(bytes: Vec<u8>) -> io::Result<String> {
   let mut gz = MultiGzDecoder::new(&bytes[..]);
   let mut s = String::new();
   gz.read_to_string(&mut s)?;
   Ok(s)
}

Implementations

impl<R> MultiGzDecoder<R>

fn header(&self) -> Option<&GzHeader>

Returns the current header associated with this stream, if it's valid.

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 stream.

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

fn into_inner(self) -> R

Consumes this decoder, returning the underlying reader.

impl<R: Read> MultiGzDecoder<R>

fn new(r: R) -> MultiGzDecoder<R>

Creates a new decoder from the given reader, immediately parsing the (first) gzip header. If the gzip stream contains multiple members all will be decoded.

Trait Implementations

impl<R: Debug> Debug for MultiGzDecoder<R>

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

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

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

impl<R: Read> Read for MultiGzDecoder<R>

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

Auto Trait Implementations

impl<R> !RefUnwindSafe for MultiGzDecoder<R>

impl<R> !UnwindSafe for MultiGzDecoder<R>

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

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

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

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

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

Blanket Implementations

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> From<T> for MultiGzDecoder<R>

fn from(t: T) -> T

Returns the argument unchanged.

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

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

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

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