-
Notifications
You must be signed in to change notification settings - Fork 163
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
Reading self-terminating streams #28
Comments
Thanks for the report! This came up in the past with #14 (I think with even the same use case!), which eventually prompted the creation of the First, although all streams and such have I agree that dealing with |
Yep, indeed. I'm glad other people are thinking along the same lines; it means I'm not totally crazy :)
Ah, perfect! Today I learned...
Yep, that'll do nicely. I'll take a stab at putting that together. |
First off, awesome library, thanks!
My use-case: reading git pack files, which contain multiple concatenated, yet undelimited, zlib/deflate streams of data. In other words, the pack files don't contain any information about the length of the streams - so to detect where the start of the next object in the pack is, I have to know exactly how many bytes the underlying deflate implementation consumed, so I can know where in the underlying file to start reading the next segment of data from.
This poses two separate problems:
In an ideal world, I think ZlibDecoder would only take a
&mut
reference to the underlyingRead
, and by some magic, when it's destroyed, it leaves that underlying stream positioned at the exact end of zlib data. This will likely involve requiring the underling stream to also implementSeek
, which in turn either requires code duplication in the API (so far as I am aware), or imposes unwanted restrictions on everyone else. I don't think that's realistic, so let's move on to option 2:Make ZlibDecoder take a
&mut
reference to the underlyingRead
. It does nothing special when it's destroyed, but it exposes an extrazlibDecoder.consumed_bytes()
method (or field, or whatever), calculated from the total bytes it's read, less what's remaining in miniz's input buffer.The last option for me is to scrap the higher-level API and directly use your miniz-sys bindings, which is ugly for me, but less ugly for everyone else.
Thoughts?
The text was updated successfully, but these errors were encountered: