diff --git a/src/gz/bufread.rs b/src/gz/bufread.rs index 679b4a7d..b3f94f38 100644 --- a/src/gz/bufread.rs +++ b/src/gz/bufread.rs @@ -277,6 +277,19 @@ impl GzDecoder { pub fn into_inner(self) -> R { self.reader.into_inner().into_inner() } + + /// Returns the number of bytes that the decompressor has consumed. + /// + /// Note that this will likely be smaller than what the decompressor + /// actually read from the underlying stream due to buffering. + pub fn total_in(&self) -> u64 { + self.reader.get_ref().total_in() + } + + /// Returns the number of bytes that the decompressor has produced. + pub fn total_out(&self) -> u64 { + self.reader.get_ref().total_out() + } } impl Read for GzDecoder { @@ -427,6 +440,19 @@ impl MultiGzDecoder { pub fn into_inner(self) -> R { self.0.into_inner() } + + /// Returns the number of bytes that the decompressor has consumed. + /// + /// Note that this will likely be smaller than what the decompressor + /// actually read from the underlying stream due to buffering. + pub fn total_in(&self) -> u64 { + self.0.reader.get_ref().total_in() + } + + /// Returns the number of bytes that the decompressor has produced. + pub fn total_out(&self) -> u64 { + self.0.reader.get_ref().total_out() + } } impl Read for MultiGzDecoder { diff --git a/src/gz/read.rs b/src/gz/read.rs index 9dbadbda..dba8c1c2 100644 --- a/src/gz/read.rs +++ b/src/gz/read.rs @@ -180,6 +180,19 @@ impl GzDecoder { pub fn into_inner(self) -> R { self.inner.into_inner().into_inner() } + + /// Returns the number of bytes that the decompressor has consumed. + /// + /// Note that this will likely be smaller than what the decompressor + /// actually read from the underlying stream due to buffering. + pub fn total_in(&self) -> u64 { + self.inner.total_in() + } + + /// Returns the number of bytes that the decompressor has produced. + pub fn total_out(&self) -> u64 { + self.inner.total_out() + } } impl Read for GzDecoder { @@ -278,6 +291,19 @@ impl MultiGzDecoder { pub fn into_inner(self) -> R { self.inner.into_inner().into_inner() } + + /// Returns the number of bytes that the decompressor has consumed. + /// + /// Note that this will likely be smaller than what the decompressor + /// actually read from the underlying stream due to buffering. + pub fn total_in(&self) -> u64 { + self.inner.total_in() + } + + /// Returns the number of bytes that the decompressor has produced. + pub fn total_out(&self) -> u64 { + self.inner.total_out() + } } impl Read for MultiGzDecoder { diff --git a/src/gz/write.rs b/src/gz/write.rs index 74d6c5ac..6643358b 100644 --- a/src/gz/write.rs +++ b/src/gz/write.rs @@ -134,6 +134,22 @@ impl GzEncoder { } Ok(()) } + + /// Returns the number of bytes that have been written to this compressor. + /// + /// Note that not all bytes written to this object may be accounted for, + /// there may still be some active buffering. + pub fn total_in(&self) -> u64 { + self.inner.data.total_in() + } + + /// Returns the number of bytes that the compressor has produced. + /// + /// Note that not all bytes may have been written yet, some may still be + /// buffered. + pub fn total_out(&self) -> u64 { + self.inner.data.total_out() + } } impl Write for GzEncoder {