barfuin
barfuin

Reputation: 17484

File size limitations of ZipOutputStream?

I am using the ZipOutputStream to create ZIP files. It works fine, but the Javadoc is quite sparse, so I'm left with questions about the characteristics of ZipOutputStream:

  1. Is there a limit for the maximum supported file sizes? Both for files contained in the ZIP and for the resulting ZIP file itself? The size argument is long, but who knows. (Let us assume that the filesystem imposes no limits.)

  2. What is the minimum input file size that justifies use of the DEFLATED method?

I will always read the resulting ZIP file using ZipInputStream.

Upvotes: 3

Views: 5674

Answers (2)

barfuin
barfuin

Reputation: 17484

The most important aspect is that in a current Java-7 JDK, ZipOutputStream creates ZIP files according to the 2012 PKZIP specification, which also includes support for ZIP64. Note that the ZIP64 features had bugs at first, but any recent version of the Java 7 JDK will be OK.

  1. The maximum file size is thus 264-1 bytes. I tried it with a 10 GB test file. This is much larger than the 4 GB of standard ZIP. I could add it to the ZIP file with no problems, also if the resulting ZIP file itself grew beyond 4 GB.

  2. The minimum file size which justifies use of the DEFLATED method is 22 bytes. This has nothing to do with the minimum ZIP file size which is incidentally also 22 bytes (for empty ZIP files). I empirically determined this number by adding strings of as of increasing length (see diagram below). Such a sequence of identical characters compresses very well, so in the real world, the break-even point will be higher.

Deflated vs. Stored

Upvotes: 8

Ahsan Mahboob Shah
Ahsan Mahboob Shah

Reputation: 4029

Following are the limits of ZIP file format:

The minimum size of a .ZIP file is 22 bytes. The maximum size for both the archive file and the individual files inside it is 4,294,967,295 bytes (232−1 bytes, or 4 GiB minus 1 byte) for standard .ZIP, and 18,446,744,073,709,551,615 bytes (264−1 bytes, or 16 EiB minus 1 byte) for ZIP64.[31]

Reference : Zip (file format)

Upvotes: 4

Related Questions