After analysing few .zip files with the .Zip file parser (http://code.google.com/p/zipparser/), I was able to find out that Archive::Zip
does not (for some reason) set the bits of General Purpose Bit Flag.
This means that .zip file members' compression levels will not be stored in the archive.
Let us reproduce it by creating two .zip files named hello-zip.zip
(created with the GNU/Linux zip
utility) and hello-az.zip
created with Archive::Zip
for comparison. Both the files contain:
Filename: hello
Content:
Hello world.
Hello world.
Hello world
Let us compress:
[alanhaggai@archer zip]$ zip -9 hello-zip.zip hello
adding: hello (deflated 54%)
#!/usr/bin/perl -w
use strict;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
my $zip = Archive::Zip->new;
my $member = $zip->addFile('hello');
$member->desiredCompressionLevel(9);
$zip->writeToFileNamed('hello-az.zip');
Now, let us compare relevant parts of the .Zip files (several of the zip_parser.conf elements were commented out for brevity):
[alanhaggai@archer zip]$ ./zip_parser hello-zip.zip
END CENTRAL DIRECTORY RECORD
--------------------------------------------------
LOCAL FILE HEADER
--------------------------------------------------
Compressed_Size ->
18
Compression_Method ->
The file is Deflated
Filename ->
hello
General_Purpose_Bit_Flag ->
Maximum (-exx/-ex) compression option was used
Uncompressed_Size ->
39
CENTRAL DIRECTORY RECORD
--------------------------------------------------
Compressed_Size ->
18
Compression_Method ->
The file is Deflated
Filename ->
hello
General_Purpose_Bit_Flag ->
Maximum (-exx/-ex) compression option was used
Uncompressed_Size ->
39
[alanhaggai@archer zip]$ ./zip_parser hello-az.zip
END CENTRAL DIRECTORY RECORD
--------------------------------------------------
LOCAL FILE HEADER
--------------------------------------------------
Compressed_Size ->
18
Compression_Method ->
The file is Deflated
Filename ->
hello
General_Purpose_Bit_Flag ->
Normal (-en) compression option was used
Uncompressed_Size ->
39
CENTRAL DIRECTORY RECORD
--------------------------------------------------
Compressed_Size ->
18
Compression_Method ->
The file is Deflated
Filename ->
hello
General_Purpose_Bit_Flag ->
Normal (-en) compression option was used
Uncompressed_Size ->
39
Both the files were compressed at level 9 (maximum compression). However, Archive::Zip
did not set the `General Purpose Bit Flag', and so, suggest: `Normal (-en) compression option was used'.
In the case of hello-zip.zip
produced by the zip
utility, the flag's bits were set and suggest: `Maximum (-exx/-ex) compression option was used'.