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

Feature Request: ZipInputStream should properly implement available() #311

Closed
timofurrer opened this issue Apr 21, 2021 · 5 comments
Closed

Comments

@timofurrer
Copy link

The https://github.com/srikanth-lingala/zip4j/blob/master/src/main/java/net/lingala/zip4j/io/inputstream/ZipInputStream.java should properly implement the InputStream::available() method preferably with the same behavior as https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipInputStream.html#available()

In the meanwhile, do you have a workaround for that?

@srikanth-lingala
Copy link
Owner

When usiing ZipInputStream, it is unfortunately not possible to calculate the available bytes in the stream. It is because you have to read the complete zip file to know the exact available size which defeats the purpose of available. The reason you have to read through the complete file is you need to know the compressed sizes of each of the entry, and this information is stored in the headers which start before the entry itself. So, to know the number of bytes remaining in the stream, you need to first know the total amount of bytes you have in the stream, and this cannot be known, as explained above, unless you first read through the complete stream. It is for this purpose as well that JDK's ZipInputStream either returns a 0 or a 1. I will probably also add something similar to zip4j's inputstream instead of returning 0 in each case.

@timofurrer
Copy link
Author

Yes, I'm aware of that. That's why I suggested to implement the 0 or 1 byte return value in the first place ;)

@srikanth-lingala
Copy link
Owner

Oops. Sorry for that :-) I read the headline, and started thinking about a solution for it without reading your message completely.

I will add your suggestion in the next release.

@timofurrer
Copy link
Author

timofurrer commented Apr 29, 2021 via email

@srikanth-lingala
Copy link
Owner

Feature added in v2.8.0 released today.

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

No branches or pull requests

2 participants