Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add continue_with function to ZlibDecoder that allows refreshing of the stream without resetting the bufreader and fix resetting of ZlibDecoder #376

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/zlib/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ impl<R> ZlibDecoder<R> {
&mut self.obj
}

/// Acquires a reference to the underlying `Decompress` instance
pub fn get_data(&self) -> &Decompress {
&self.data
}

/// Acquires a mutable reference to the underlying `Decompress` instance
pub fn get_data_mut(&mut self) -> &mut Decompress {
&mut self.data
}

/// Consumes this decoder, returning the underlying reader.
pub fn into_inner(self) -> R {
self.obj
Expand Down
16 changes: 16 additions & 0 deletions src/zlib/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,22 @@ impl<R> ZlibDecoder<R> {
self.inner.get_mut().reset(r)
}

/// Resets the state of the decoder entirely
/// Opposed to `reset`, this function takes into account that there was
/// previously a custom Decompress in place
///
/// `zlib_header` should be whatever was used before in `new_with_decompress`
pub fn reset_on_custom(&mut self, r: R, zlib_header: bool) -> R {
self.inner.get_data_mut().reset(zlib_header);
self.inner.get_mut().reset(r)
}

/// Resets the stream for another, without wiping the bufreader.
/// Use this when your 2nd stream is dependant on previous' streams.
pub fn continue_read(&mut self, r: R) -> R {
self.inner.get_mut().reset(r)
}

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