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

Provide something like len() for GzEncoder and GzDecoder #170

Open
kolbma opened this issue Oct 25, 2018 · 4 comments
Open

Provide something like len() for GzEncoder and GzDecoder #170

kolbma opened this issue Oct 25, 2018 · 4 comments

Comments

@kolbma
Copy link

kolbma commented Oct 25, 2018

Hi,
would be nice to know the size of the extracted data, although there is an overflow after 4GB.
Or is it available and have not found it?!

Thanks

@alexcrichton
Copy link
Member

Thanks for the report! I don't think this is something that can be implemented though? Deflate streams don't know how big they're going to become, such information would have to be sent through a different channel alongside the stream to learn that

@oyvindln
Copy link
Contributor

If you mean the amount of bytes extracted so far, the underlying encoder does know. The counter may be 32-bit though. It's used when decompressing gzip-wrapped streams as they have a 32-bit length check value at the end. It's not available from the read/write structs though.

Knowing the extracted length before extracting everything is not really possible though.

@kolbma
Copy link
Author

kolbma commented Oct 29, 2018

Yes think of the last 4 bytes. I've implemented this for me to get the value and do some proof. I thought it would be nice to have this in-build in flate2.
For sure this is not possible if the input is a stream and you have not got the last 4 bytes. So there would be the requirement of some error handling.
But this should be possible:

extern crate flate2;

use std::io::prelude::*;
use flate2::read::GzDecoder;

fn main() {
    let mut d = GzDecoder::new("...".as_bytes());
    let mut s = String::new();
    d.read_to_string(&mut s).unwrap();
    let sizefooter: usize = d.get_size_of_footer().unwrap();  // <=====
    println!("{}", s);
}

@alexcrichton
Copy link
Member

Oh hm so you're looking to learn the size of the stream that was inflated after decompression has finished entirely? I think we could certainly add a method for that if one hasn't been added already!

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

3 participants