[
https://issues.apache.org/jira/browse/COMPRESS-508?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17081114#comment-17081114
]
Peter Lee commented on COMPRESS-508:
------------------------------------
> _Is it at least possible to detect the type of the ZIP file ("STORE") so that
>I will know if I should use a workaround?_
The compression method can be read by entry.getMethod(). In your case, it is
0(STORED).
I believe you are still not fully understood about the case you are coming
across. A entry using STORED does not mean you can not know the size of the
entry before extracting it. It happens ONLY when you are using STORED + Data
Descriptor(this is important) + ZipArchiveInputStream(if you inist using input
stream) - in this case you can only get the size after you extract the entry.
> _But is it possible to do it?_
If you are talking about reading the zip more than once using input stream, I
believe it's impossible. You can still cache all the content from the input
stream and use ZipFile to do that.
>From my view, developing such kind of API(reading from the input stream more
>than once to get all the entries) means a lot of work. And it's too
>complicated for users(when and why do we need to use this?). But it can only
>be used in a few cases. It's not worthy.
> Provide an API that can read ZIP archives in two passes over a stream
> ---------------------------------------------------------------------
>
> Key: COMPRESS-508
> URL: https://issues.apache.org/jira/browse/COMPRESS-508
> Project: Commons Compress
> Issue Type: Improvement
> Components: Archivers
> Affects Versions: 1.20
> Environment: Android 9 and Android 10, on both emulator and real
> device .
> Reporter: AD_LB
> Priority: Major
> Labels: zip
> Attachments: 2020-03-31_20-53-36.png, 2020-04-01_18-28-19.mp4,
> ZipTest.zip, ZipTest2.zip, ZipTest3.zip, test.zip
>
>
> I'm trying to use ZipArchiveInputStream to iterate over the items of a zip
> file (which may or may not be a real file on the file-system, which is why I
> use a stream), optionally creating a stream from specific entries.
> One of the operations I need is to get the size of the files within.
> For some reason, it fails to do so. Not only that, but it throws an exception
> when I'm done with it:
> {code:java}
> Error:org.apache.commons.compress.archivers.zip.UnsupportedZipFeatureException:
> Unsupported feature data descriptor used in entry ...
> {code}
> I've attached here 3 files:sample project, the problematic zip file (remember
> that you need to put it in the correct path and grant storage permission),
> and a screenshot of the issue.
> Note that if I open the file using a third party PC app (such as
> [7-zip|https://www.7-zip.org/] ), it works fine, including showing the file
> size inside.
> Files:
> !2020-03-31_20-53-36.png![^test.zip]
> [^ZipTest.zip]
> Here's the relevant code (kotlin) :
>
> {code:java}
> thread {
> try {
> val file = File("/storage/emulated/0/test.zip")
> ZipArchiveInputStream(FileInputStream(file)).use {
> while (true) {
> val entry = it.nextEntry ?: break
> Log.d("AppLog", "entry:${entry.name} ${entry.size} ")
> }
> }
> Log.d("AppLog", "got archive ")
> } catch (e: Exception) {
> Log.d("AppLog", "Error:$e")
> e.printStackTrace()
> }
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)