Calling Reader.Next() without reading file #3
Copy link
Copy link
Open
Description
Hey, thanks for a great effort on this library, as far as I can find it's the only native Go library able to read 7z files!
I was seeing some errors when trying to use it to read just a single file from a 7z archive. Turns out that you need to read all the streams in the archive, even if you are not going to use them. I don't know if this is a feature of the 7z file format or not, but I think the documentation should either be updated to make it clear that you need to read until io.EOF from the Reader before calling Next() or the code should be updated to be able to handle this.
I don't know where to start working on this, but if you can point me in a direction, I can try to submit a pull request.
Once again, thanks for a great library!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
saracen commentedon Feb 19, 2020
Hi @rHermes
Sorry for the delay, I've only just noticed your comment.
The library should handle this on your behalf, however, I've had issues with the code responsible for it in the past and it won't surprise me if there's still a bug somewhere.
When 7z uses solid blocks, multiple files are combined and compressed together. This means that when it comes to reading a specific file in the compressed block, all files compressed before it still need to be read and decompressed. The code responsible for this is actually in a separate library - github.com/saracen/solidblock - and should read and discard the unneeded data if the calling code hasn't been reading all of the files. To complicate matters, we don't just discard on each Next() call, as 7z can have multiple solid blocks, and it'd be quite wasteful to decompress and discard data in blocks the user wasn't interested in.
I'll try to see if I can reproduce the bug and have look this week. Thank you for the report!
ajnavarro commentedon Jun 10, 2020
A tentative fix here: #5