rust-lang / flate2-rs

DEFLATE, gzip, and zlib bindings for Rust
https://docs.rs/flate2
Apache License 2.0
895 stars 161 forks source link

Why does `reset()` exist for `DeflateDecoder` but no `GzDecoder`? #313

Open aldanor opened 2 years ago

aldanor commented 2 years ago

It's not a huge deal, but GzDecoder::new() has a heap allocation and if you're decompressing disjoint chunks from many readers, not being able to simply reset an existing decoder is a bit depressing, especially given that it's possible for DeflateDecoder. Wonder if it would make sense to add GzDecoder::reset(reader) method?

smabie commented 2 years ago

Also looking for this feature, am reading from a gzip compressed websocket and would really like to avoid the header heap allocation for each message since I'm working on an extremely low latency application.

jongiddy commented 1 year ago

Not what you asked for, but does https://github.com/rust-lang/flate2-rs/pull/323 fix this for you? It rewrites the gzip header parsing so that it does not allocate unless optional fields (extras, filename, comment, crc) are present.