-
Notifications
You must be signed in to change notification settings - Fork 36
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
Not decompressing the full stream #57
Comments
Thanks for reporting this! I'll try to reproduce this and pinpoint the error |
Ok so I can definitely reproduce this. Interestingly there are at least two issues here:
This suggests that
What's weird is that the streaming decoder apparently catches on to the error way earlier than the usage of the FrameDecoder. Anyways just wanted to let you know this isn't your fault. I'll investigate this further and see what's going on here. Update: Apparently ruzstd does decode the contents correctly but gets confused by something at the very end of the original file, checksumming the output of the
|
Okay so this is (thankfully) way more mundane than I thought. The first error with the weird error was just a bookkeeping thing not in the libary code but in the binary code related to skippable frames that did not manifest for skippable frames in the middle of a file, but only when they are the last frame. I pushed a fix for that. (But that did not affect your usage of the library) The second issue (that is actually related to your issue) is this: The StreamingDecoder is coded in a way that it expects the reader to only contain one frame, not a stream of frames. So it decodes only the first frame in the file and then stops. Which apparently results in 66k of data being decoded. So you need to make a loop that continues to construct streaming decoders until the whole file has been processed. The reason the StreamingDecoder does not do this is that a reader has no function on it that can tell you if it's going to return any more bytes or not. |
Thanks a lot for the investigation! Will you accept a PR that adds this tidbit to the documentation? |
I tried the latest master, and get a similar issue as you described, the file decompresses correctly, but I get an error, however a different one. |
Sure :)
This error signals that a skippable frame has been encountered, the first number is the magic number in the frame header (used to identify what kind of content is in this frame, opaque to the zstd decoder) and the second one is the amount of bytes to jump forward. Maybe this should have been solved a bit cleaner instead of using an error... |
The error outcome in this case is not obvious, but I think it is fixable with a little bit of documentation. I don't think this makes a very ergonomic API, ideally I would expect the streaming reader to decode the full file, dealing with zstd peculiarities under the hood, but I guess the implementation requires a bit more thinking |
I also understand that someone might need access to these skip frames, but I would expect this to be achievable through a different API maybe. Designing API's are difficult 🙃 |
The problem here is that the decoder just deals with a reader. This could also be a e.g. a tcp socket where you probably want to stop after each frame because the decoded stream is potentially endless. The StreamDecoder is still a pretty low-level abstraction. I could maybe include a FileDecoder that only deals with files, which could actually go ahead an gloss over all those details. But then again that is kind of a feature creep and introduces more complexity because this would depend on stdlib whereas this libary is also available for no_std environments |
Inside this zip archive there is a zstandard compressed file, produced by blender. (I had to compress it into a zip archive, because github does not allow uploading random binaries)
zstd
crate, when used to decompress, produces a buffer of length924460
, while ruzstd only decompresses66804
bytesThe code to repro:
versions used
Am I using it wrong or is there a bug?
Thank you for maintaining this! ❤️
The text was updated successfully, but these errors were encountered: