Skip to content

Commit

Permalink
Merge pull request #278 from tobz/tobz/expose-encoder-stats-methods
Browse files Browse the repository at this point in the history
Expose `total_in`/`total_out` from underlying `flate2` encoder types.
robjtede authored May 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 94efb21 + 1fcbb9c commit fd77c55
Showing 7 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/codec/flate/encoder.rs
Original file line number Diff line number Diff line change
@@ -17,6 +17,10 @@ impl FlateEncoder {
}
}

pub(crate) fn get_ref(&self) -> &Compress {
&self.compress
}

fn encode(
&mut self,
input: &mut PartialBuffer<impl AsRef<[u8]>>,
4 changes: 4 additions & 0 deletions src/codec/zlib/encoder.rs
Original file line number Diff line number Diff line change
@@ -14,6 +14,10 @@ impl ZlibEncoder {
inner: crate::codec::FlateEncoder::new(level, true),
}
}

pub(crate) fn get_ref(&self) -> &crate::codec::FlateEncoder {
&self.inner
}
}

impl Encode for ZlibEncoder {
4 changes: 4 additions & 0 deletions src/futures/bufread/generic/encoder.rs
Original file line number Diff line number Diff line change
@@ -47,6 +47,10 @@ impl<R: AsyncBufRead, E: Encode> Encoder<R, E> {
self.project().reader
}

pub(crate) fn get_encoder_ref(&self) -> &E {
&self.encoder
}

pub fn into_inner(self) -> R {
self.reader
}
4 changes: 4 additions & 0 deletions src/futures/write/generic/encoder.rs
Original file line number Diff line number Diff line change
@@ -51,6 +51,10 @@ impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
self.project().writer.get_pin_mut()
}

pub(crate) fn get_encoder_ref(&self) -> &E {
&self.encoder
}

pub fn into_inner(self) -> W {
self.writer.into_inner()
}
10 changes: 10 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -131,6 +131,16 @@ macro_rules! algos {
),
}
}

/// Returns the total number of input bytes which have been processed by this compression object.
pub fn total_in(&self) -> u64 {
self.inner.get_encoder_ref().get_ref().get_ref().total_in()
}

/// Returns the total number of output bytes which have been produced by this compression object.
pub fn total_out(&self) -> u64 {
self.inner.get_encoder_ref().get_ref().get_ref().total_out()
}
}
{ @dec }
);
4 changes: 4 additions & 0 deletions src/tokio/bufread/generic/encoder.rs
Original file line number Diff line number Diff line change
@@ -47,6 +47,10 @@ impl<R: AsyncBufRead, E: Encode> Encoder<R, E> {
self.project().reader
}

pub(crate) fn get_encoder_ref(&self) -> &E {
&self.encoder
}

pub fn into_inner(self) -> R {
self.reader
}
4 changes: 4 additions & 0 deletions src/tokio/write/generic/encoder.rs
Original file line number Diff line number Diff line change
@@ -51,6 +51,10 @@ impl<W: AsyncWrite, E: Encode> Encoder<W, E> {
self.project().writer.get_pin_mut()
}

pub(crate) fn get_encoder_ref(&self) -> &E {
&self.encoder
}

pub fn into_inner(self) -> W {
self.writer.into_inner()
}

0 comments on commit fd77c55

Please sign in to comment.