Skip to content
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

Calling Reader.Next() without reading file #3

Open
rHermes opened this issue Jan 25, 2020 · 2 comments
Open

Calling Reader.Next() without reading file #3

rHermes opened this issue Jan 25, 2020 · 2 comments

Comments

@rHermes
Copy link

rHermes commented Jan 25, 2020

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!

@saracen
Copy link
Owner

saracen commented 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
Copy link

A tentative fix here: #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants