Skip to content

Commit

Permalink
Implemented multi member gz decoder
Browse files Browse the repository at this point in the history
Added a MultiDecoderReader and MultiDecoderReaderBuf to gz. I moved
the read header code to a separate function to avoid code duplication.

In order to keep the reader but reset the decoder a reset_data method
has been added to deflate.rs and a reset method to the CrcReader.

Tests for multimember gz files are in the test directory.
  • Loading branch information
veldsla committed Jun 14, 2016
1 parent 395d15e commit 7a2f0e7
Show file tree
Hide file tree
Showing 7 changed files with 274 additions and 85 deletions.
9 changes: 9 additions & 0 deletions src/crc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ impl Crc {
ffi::mz_crc32(self.crc, data.as_ptr(), data.len() as libc::size_t)
};
}

pub fn reset(&mut self) {
self.crc = 0;
self.amt = 0;
}
}

impl<R: Read> CrcReader<R> {
Expand All @@ -56,6 +61,10 @@ impl<R: Read> CrcReader<R> {
pub fn inner(&mut self) -> &mut R {
&mut self.inner
}

pub fn reset(&mut self) {
self.crc.reset();
}
}

impl<R: Read> Read for CrcReader<R> {
Expand Down
8 changes: 8 additions & 0 deletions src/deflate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ impl<R: BufRead> DecoderReaderBuf<R> {
mem::replace(&mut self.obj, r)
}

/// Resets the state of this decoder's data
///
/// This will reset the internal state of this decoder. It will continue
/// reading from the same stream.
pub fn reset_data(&mut self) {
self.data = Decompress::new(false);
}

/// Acquires a reference to the underlying stream
pub fn get_ref(&self) -> &R {
&self.obj
Expand Down
Loading

0 comments on commit 7a2f0e7

Please sign in to comment.