ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Zip task does not store file size
Date Wed, 03 Apr 2002 14:37:02 GMT
On Mon, 18 Mar 2002, Christoph Behnke <> wrote:

> The zip task does not store the uncompressed file size
> in the generated zip file. This is not mandatory in
> zip file format but other tools like winzip are
> storing the uncompressed file size in the zip file.

Sorry for taking so long to answer.

When I talk about the ZIP format, I'm basing what I say on

The zip classes Ant uses take advantage of the Data Descriptor that
one should use if one cannot seek the files being compressed.  Java's
built-in classes do the same BTW.

If you do so, you set "bit 3 of the general purpose bit flag", which
again implies 

>>  Bit 3: If this bit is set, the fields crc-32, compressed size
>>         and uncompressed size are set to zero in the local
>>         header.  The correct values are put in the data descriptor
>>         immediately following the compressed data.

So Ant is supposed to set these fields in the local file header to 0.
Ant *does* store them both in the data descriptor and in the central
directory file header - the later is used as the authoritative source
by InfoZip.

The question that remains is, why does Ant use this feature?

Well, you don't know the CRC and the compressed size before you've
compressed the file.  And in reality you cannot trust File.length() as
it may (and will) return bad values on some OSes/JVMs - that means
that you don't really know the uncompressed size before you've
compressed the file either.

Compressing the complete file in memory may be too expensive, so Ant's
zip classes (again just like directly write the data
into the archive while they compress the file.  As you have to write
the local file header before you write the data, Ant doesn't know the
size information at this point and cannot insert it.

> Is there a possibility to let the ant zip taks store
> the file size?

It does so at two places and InfoZip based zips (like the one shipping
with Linux distributions) can read it:

[bodewig@bodewig jakarta-ant]$ unzip -l $ANT_HOME/lib/ant.jar
Archive:  /home/bodewig/ASF/jakarta/jakarta-ant/bootstrap/lib/ant.jar
  Length     Date   Time    Name
 --------    ----   ----    ----
        0  04-03-02 15:10   META-INF/
      439  04-03-02 15:10   META-INF/MANIFEST.MF

so WinZIP isn't doing as good as it could 8-)


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message