Are files in a .zip file always compressed?

428 Views Asked by At

At work I'm implementing a new webservice that works with files. The specifications say that we should not accept .zip files if they are compressed.

Is there such a thing as a not compressed .zip file? If yes, what do you think would be the best way to detect one using Java (1.8)?

2

There are 2 best solutions below

2
On

Yes, a zip can be uncompressed. In fact, early .jar files were just uncompressed .zip files.

The ZipEntry class has getMethod to get the compression method of an entry. One of the options is STORED (e.g., not compressed).

0
On

zip is just a container-format, which can hold many possible types of compressed and uncompressed entries.

Often files are deflated, which means, they are compressed. Others are simply stored, which means they are uncompressed.