Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

alanhaggai (8497)

alanhaggai
  (email not shown publicly)
http://alanhaggai.org/
Yahoo! ID: alan_haggai (Add User, Send Message)
Jabber: alanhaggai@gmail.com

Journal of alanhaggai (8497)

Friday October 24, 2008
01:15 PM

Archive::Zip does not set General Purpose Bit Flag

[ #37727 ]

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

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.