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

Implemented total_in() and total_out() for GzDecoder, GzEncoder and MultiGzDecoder #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions src/gz/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ impl<R> GzDecoder<R> {
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<R: BufRead> Read for GzDecoder<R> {
Expand Down Expand Up @@ -427,6 +440,19 @@ impl<R> MultiGzDecoder<R> {
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<R: BufRead> Read for MultiGzDecoder<R> {
Expand Down
26 changes: 26 additions & 0 deletions src/gz/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ impl<R> GzDecoder<R> {
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<R: Read> Read for GzDecoder<R> {
Expand Down Expand Up @@ -278,6 +291,19 @@ impl<R> MultiGzDecoder<R> {
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<R: Read> Read for MultiGzDecoder<R> {
Expand Down
16 changes: 16 additions & 0 deletions src/gz/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ impl<W: Write> GzEncoder<W> {
}
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<W: Write> Write for GzEncoder<W> {
Expand Down