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>
impl<'a, Input: BufRead> Reader<'a, Input>
Sourcepub fn new(r: &'a mut Input) -> Result<Self>
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.
Sourcepub fn reset(&mut self, r: &'a mut Input) -> Result<()>
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.
Sourcepub fn reset_state(&mut self) -> Result<()>
pub fn reset_state(&mut self) -> Result<()>
reset_state is similar to reset, but reuses the underlying reader.
Sourcepub fn multistream(&mut self, ok: bool)
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.
Trait Implementations§
Source§impl<Input: BufRead> Read for Reader<'_, Input>
impl<Input: BufRead> Read for Reader<'_, Input>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more