flate2-rs icon indicating copy to clipboard operation
flate2-rs copied to clipboard

Provide Seek / offset pointer in GzDecoder

Open gwbres opened this issue 3 years ago • 4 comments
trafficstars

Hello,

I would like to enhance the GzDecoder with the std::io::Seek trait and std::io::rewind() capacities, to rewind the file although we might already have uncompressed some data. Is that even doable ?

My first basic attempt here, I implement the Seek trait. Let's say I uncompressed a first line, then call Seek(pos=0) to rewind, the first line is forever lost and cannot be uncompressed a second time.

My second attempt here I try to implement something that would rewind right after the .gz header (that we would never read again) and try to reset the FSM at the beginning of the file Body. Same results, it's like none of the things I do have an impact. I guess I'm missing some important attributes to reset, but I'm having a hard time understanding the code.

Any advice ?

gwbres avatar Jul 26 '22 07:07 gwbres

I'd like to request this feature as well.

zlib.h already contains related functions:

https://github.com/madler/zlib/blob/21767c654d31d2dccdde4330529775c6c5fd5389/zlib.h#L1849-L1863

noonchen avatar Oct 05 '22 03:10 noonchen

Would also like to see this.

milesj avatar Jun 01 '23 21:06 milesj

I would also like to see this! Would be a game changer

hderms avatar Jun 02 '23 17:06 hderms

To anyone looking for a solution: in case you really need Seek and you dont mind RAM overhead -- you can use SeekableReader. It is Read + Seek wrapper around Read that caches read data within internal buffer.

IriaSomobu avatar Jan 04 '24 15:01 IriaSomobu