Reader

Struct Reader 

Source
pub struct Reader<'a, Input: BufRead> {
    pub header: Option<Header>,
    /* private fields */
}
Expand description

A Reader can be used to retrieve uncompressed data from a gzip-format compressed file.

In general, a gzip file can be a concatenation of gzip files, each with its own header. Reads from the Reader return the concatenation of the uncompressed data of each. Only the first header is recorded in the Reader fields.

Gzip files store a length and checksum of the uncompressed data. The Reader will return an ErrChecksum when Read reaches the end of the uncompressed data if it does not have the expected length or checksum. Clients should treat data returned by Read as tentative until they receive the io.EOF marking the end of the data.

Fields§

§header: Option<Header>

Implementations§

Source§

impl<'a, Input: BufRead> Reader<'a, Input>

Source

pub fn new(r: &'a mut Input) -> Result<Self>

new creates a new Reader reading the given reader.

Make sure that the reader implements buffering otherwise the performance can be low. You can use std::io::BufReader to add buffering to any reader.

The Reader.header fields will be valid in the Reader returned. If Reader.header is None, then there is no stream available.

Examples found in repository?
examples/gunzip.rs (line 18)
14fn extract_with_ggstd(path: &str) -> std::io::Result<String> {
15    use ggstd::compress::gzip;
16
17    let mut f = BufReader::new(File::open(path)?);
18    let mut gzip = gzip::Reader::new(&mut f)?;
19    let mut content = String::new();
20    gzip.read_to_string(&mut content)?;
21    Ok(content)
22}
Source

pub fn reset(&mut self, r: &'a mut Input) -> Result<()>

reset discards the Reader self’s state and makes it equivalent to the result of its original state from Reader::new, but reading from r instead. This permits reusing a Reader rather than allocating a new one.

Source

pub fn reset_state(&mut self) -> Result<()>

reset_state is similar to reset, but reuses the underlying reader.

Source

pub fn multistream(&mut self, ok: bool)

multistream controls whether the reader supports multistream files.

If enabled (the default), the Reader expects the input to be a sequence of individually gzipped data streams, each with its own header and trailer, ending at EOF. The effect is that the concatenation of a sequence of gzipped files is treated as equivalent to the gzip of the concatenation of the sequence. This is standard behavior for gzip readers.

Calling Multistream(false) disables this behavior; disabling the behavior can be useful when reading file formats that distinguish individual gzip data streams or mix gzip data streams with other data streams. In this mode, when the Reader reaches the end of the data stream, Read returns io.EOF. The underlying reader must implement io.ByteReader in order to be left positioned just after the gzip stream. To start the next stream, call self.reset(r) followed by self.Multistream(false). If there is no next stream, self.reset(r) will return io.EOF.

Source

pub fn close(&mut self) -> Result<()>

close closes the Reader. It does not close the underlying io.Reader. In order for the GZIP checksum to be verified, the reader must be fully consumed until the io.EOF.

Source

pub fn is_eof(&self) -> bool

is_eof returns true if there are no more gzip steams available.

Trait Implementations§

Source§

impl<Input: BufRead> Read for Reader<'_, Input>

Source§

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

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
1.36.0 · Source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
Source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · Source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Reads all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · Source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Reads all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · Source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Reads the exact number of bytes required to fill buf. Read more
Source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
Source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Reads the exact number of bytes required to fill cursor. Read more
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Read. Read more
1.0.0 · Source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · Source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · Source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
Source§

impl<Input: BufRead> Reader for Reader<'_, Input>

Source§

fn read(&mut self, p: &mut [u8]) -> IoRes

read implements io.Reader, reading uncompressed bytes from its underlying Reader.

Auto Trait Implementations§

§

impl<'a, Input> Freeze for Reader<'a, Input>

§

impl<'a, Input> !RefUnwindSafe for Reader<'a, Input>

§

impl<'a, Input> Send for Reader<'a, Input>
where Input: Send,

§

impl<'a, Input> Sync for Reader<'a, Input>
where Input: Sync,

§

impl<'a, Input> Unpin for Reader<'a, Input>

§

impl<'a, Input> !UnwindSafe for Reader<'a, Input>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.