srikanth-lingala / zip4j

A Java library for zip files and streams
Apache License 2.0
2.06k stars 310 forks source link

Extracting specific files from Zip using "stream" mechanism #471

Closed castrob closed 2 years ago

castrob commented 2 years ago

Hi!

I would like to know if it is possible to access the files in a Zip File using the "stream" mechanism directly, instead of having to go through each file until I reach the designated one.

Example: I have the files: "/a/1.txt" "/a/2.txt" "/a/3.txt"

Imagine that iterating over the Zip File to get the "/a/3.txt" file, I've already gone through files 1 and 2. Would it be possible to store the position of each file in a way that the next time I need to read it, it goes straight to its position ?

srikanth-lingala commented 2 years ago

Unfortunately, that's not how stream works. A stream has to read through the complete content of the underlying stream to reach a particular position. It is quite different in case of RandomAccessFile, using which you can jump to any position in a file. But with a stream, we have to read through the content.