LineAxe has asked for the wisdom of the Perl Monks concerning the following question:

i have ubuntu jaunty on a 32 bit machine and a 64 bit machine . when I write code to add files to zip and then write the zip file ,the code executes with no errors (0h) but then it only creates a 22 byte zip file . it does it on two different machines . the code is very basic as in all the examples i have looked at but , no go .. Some software I was using had the same problem so I wrote up a perl file to test it and found out archive::zip wasnt zipping up any of the files !! HHHHHHHHHHHHHHHEEEEEEEEEEEEEEEEEEELLLLLLLLL PP?

Replies are listed 'Best First'.
Re: archive:zip and jaunty ubuntu
by moritz (Cardinal) on Oct 28, 2009 at 07:39 UTC
Re: archive:zip and jaunty ubuntu
by gmargo (Hermit) on Oct 28, 2009 at 17:42 UTC

    Archive::Zip wasn't adding any files because you didn't give it any. 22 bytes is the size of an empty zip file.

    Here's demo code: create empty file and see that it's 22 bytes.

    use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); unless ( $zip->writeToFileNamed("someZip1.zip") == AZ_OK ) { die "write error: $!"; }
    Same code, but add one file named "perl150.pl".
    use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $zip = Archive::Zip->new(); my $file_member = $zip->addFile( "perl150.pl" ); unless ( $zip->writeToFileNamed("someZip2.zip") == AZ_OK ) { die "write error: $!"; }

    And the output files:

    $ ls -l someZip* -rw-r--r-- 1 gmargo gmargo 22 Oct 28 10:39 someZip1.zip -rw-r--r-- 1 gmargo gmargo 335 Oct 28 10:34 someZip2.zip $ unzip -v someZip1.zip Archive: someZip1.zip warning [someZip1.zip]: zipfile is empty $ unzip -v someZip2.zip Archive: someZip2.zip Length Method Size Ratio Date Time CRC-32 Name -------- ------ ------- ----- ---- ---- ------ ---- 282 Defl:N 217 23% 10-28-09 10:34 ade4be0c perl150.pl -------- ------- --- ------- 282 217 23% 1 file