You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jason Harrop <jh...@gmail.com> on 2018/07/20 00:21:42 UTC

(compress) read data descriptor?

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...

Re: (compress) read data descriptor?

Posted by Stefan Bodewig <bo...@apache.org>.
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: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org