From 5b86343cd582ea8e7af8001b22376e5ba4ac0c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pi=C3=A8rre?= <77776198+PierreV23@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:37:01 +0200 Subject: [PATCH 1/3] Add `continue_read` function in ZlibDecoder --- src/zlib/read.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/zlib/read.rs b/src/zlib/read.rs index b65418be..05a9e8a5 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -222,6 +222,12 @@ impl ZlibDecoder { 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() From 0ce8990ae6e873e5440d21f5ecba36ac71fc3abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pi=C3=A8rre?= <77776198+PierreV23@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:55:12 +0200 Subject: [PATCH 2/3] Fix resetting of ZlibDecoder and underlying system --- src/zlib/bufread.rs | 10 ++++++++++ src/zlib/read.rs | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/zlib/bufread.rs b/src/zlib/bufread.rs index aa8af64f..3ab2396c 100644 --- a/src/zlib/bufread.rs +++ b/src/zlib/bufread.rs @@ -215,6 +215,16 @@ impl ZlibDecoder { &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 diff --git a/src/zlib/read.rs b/src/zlib/read.rs index 05a9e8a5..517ddfbb 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -222,6 +222,17 @@ impl ZlibDecoder { 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 { From 013e79de11c7006e39fb5ec1ae7df9d2a7968977 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pi=C3=A8rre?= <77776198+PierreV23@users.noreply.github.com> Date: Wed, 13 Sep 2023 11:04:20 +0200 Subject: [PATCH 3/3] cargo fmt --- src/zlib/read.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/zlib/read.rs b/src/zlib/read.rs index 2c05aa06..f53509f0 100644 --- a/src/zlib/read.rs +++ b/src/zlib/read.rs @@ -222,11 +222,10 @@ impl ZlibDecoder { 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);