(compress) read data descriptor?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

(compress) read data descriptor?

Jason Harrop
Given a ZipFile, its easy to read the size of ZipArchiveEntry

How to do this when using ZipArchiveInputStream?

The documentation says: ZipFile has access to the central directory and can
extract entries using the data descriptor reliably. The same is true for
ZipArchiveInputStream as long as the entry is DEFLATED.

Assuming the entry is DEFLATED, I'm not sure how to read that?  thanks...
Reply | Threaded
Open this post in threaded view
|

Re: (compress) read data descriptor?

Stefan Bodewig
On 2018-07-20, Jason Harrop wrote:

> Given a ZipFile, its easy to read the size of ZipArchiveEntry

> How to do this when using ZipArchiveInputStream?

> The documentation says: ZipFile has access to the central directory and can
> extract entries using the data descriptor reliably. The same is true for
> ZipArchiveInputStream as long as the entry is DEFLATED.

TBH the paragraph doesn't make much sense to me but has very likely been
written by my former self.

> Assuming the entry is DEFLATED, I'm not sure how to read that?

ZipFile uses random access and can read size and crc information from
anywhere inside of the archive.

ZipArchiveInputStream reads a stream byte by byte and can only provide
you with information it has read by the time you ask for it. The
structure of a ZIP archive has meta data in the so called local file
header followed by the actual content of each entry. Sometimes this
local file header contains the entry's size and you can ask
ZipArchiveEntry for its size before reading the entry.  Under certain
circumstances - and using DEFLATE is one of them - the size can be
stored after the entry data inside the so called data descriptor. If the
archive uses the data descriptor ZipArchiveEntry's getSize can only
return "unknown" until you have read all data of the entry. Once you
have read the entry's content completely, ZipArchiveEntry will know the
size. This is what the "Note" in
https://commons.apache.org/proper/commons-compress/javadocs/api-release/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.html#getSize--
says.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]