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

Feature request: add FrameDecoder.total_in() and .total_out() to return the number of compressed bytes and uncompressed_bytes read so far #157

Open
DeflateAwning opened this issue Apr 18, 2024 · 3 comments

Comments

@DeflateAwning
Copy link

Feature request: add the following methods:

  1. FrameDecoder frame_decoder.total_in(): returns the number of compressed bytes which have entered the decompressor so far
  2. FrameDecoder frame_decoder.total_out(): returns the number of decompressed bytes outputed by the compressor so far

These values appear to be stored easily as private variables in the FrameDecoder struct. It would be awesome if they were accessible.

Reasoning

  1. The comparable XzDecoder in the xz2 library has this exact setup.
  2. It would make creating progress report messages very straight-forward.

Other Notes

  • Perhaps creating a TotalInOut trait for this would be cool?
  • Ideally, ensure that reading these values does not require a mutable reference to the FrameDecoder. Seems obvious, but getting the current seek location in a File requires a mutable reference, so I guess it's not as obvious as you'd think.
@PSeitz
Copy link
Owner

PSeitz commented Apr 18, 2024

I'd accept a pull request for that.

seek changes the state of File and is therefore mut.

@DeflateAwning
Copy link
Author

In your opinion, should I create a trait for this, or just implement the functions? I'm pretty new to Rust, and don't have a great grasp on effective library design yet. I'll work on implementing this.

Re seek (which isn't relevent here) - file_reader.stream_position() requires a mutable reference because it calls self.seek(SeekFrom::Current(0)) under the hood. This call does not actually seek (i.e., it does not move the read "pointer"). It frustrates me.

@PSeitz
Copy link
Owner

PSeitz commented May 10, 2024

I think just the functions should be fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants