-
Notifications
You must be signed in to change notification settings - Fork 162
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
Replace interior Reader without resetting decompress data #276
Comments
I would love this exact same feature but for ZlibEncoder - right now I can't reuse a ZlibEncoder object, but using Compress directly (https://gist.github.com/Gelbpunkt/44a6fb4cfe15f15e4c3757416b7021b1) doesn't work when I reuse the object. |
I am probably not following on some intricacies of the problem, but wonder if it's possible to create a custom I'd find that, in theory, more suitable as first step towards solving this particular problem as it's much less involved. Of course, it also delegates the hard parts of managing the internal decompressor state correctly which certainly wouldn't be trivial, but should be possible. |
Tried swapping out the internal reader for GzDecoder using interior mutability but it does not work.
I don't think this can be done without additional support from the library itself. |
Couldn't a multi-member (continuous) stream be accomplished by a MultiGzDecoder. I think what would really help here is an example program with real (but minimal) input data. |
AFAICT, MultiGzDecoder is for gzip having multiple files inside it which is not the usecase here. The usecase here, for example, is to download huge gzip files using range requests. Reqwest's Response object implements Read, so it can be used with GzDecoder or MultiGzDecoder, but once a given response is decoded you make another range request to get the next piece of data and decode it in a streaming fashion, probably because the data is huge and you want to filter out some stuff or parse it directly etc. But because every range request yields a different response, an ability to swap the internal reader is required while keeping the internal state sane. I do have some code for the same but I don't have any public gzip url where i can try this on. Let me see if I can do something about the example code. |
Perhaps handling this as a WouldBlock error like this test does could work? Lines 332 to 350 in 1a0daec
Then on error the next chunk can be filled in. |
Either:
|
I have created a repo with an example program: https://github.com/nc-x/flate-276
The issue is that when you try reading from GzDecoder, it will simply go past the end of the partial data which it was provided and fail, which is expected because technically the input is incomplete and hence invalid. So, basically the first reading itself fails and you do not even get to the point where you can swap underlying readers or return 0 etc. AFAICT end users of GzDecoder cannot do anything about this and there needs to be a way tell GzDecoder that it will be given partial data, so it should't fail. Have not tried your 2nd solution and am busy for a couple of days now but presumably that would have the same issue as well? |
I made a pull request to your repo to demonstrate the correct solution using a The |
thanks |
If I'm parsing a continuous encoded stream that is (unfortunately) divided up across several successive inputs, my only option appears to be using the Decompress object directly, which is a huge hassle without access to the zio:: functions.
It seems like it would be easy to create a "replace" method identical to the various "reset" methods, but with the
reset_decoder_data(self);
call removed. That way, I could switch out one Read object for the next while preserving the stream state.The text was updated successfully, but these errors were encountered: