excellent question.
You are checking the compressionMethod, which is returning 8. This is good, as Archive::Zip only supports one compression method.
If we check the compressionLevel, we should get the desired information. When I check it on the file I'm adding, I see default (-1) and then I set it and see what I set (9). How do we check this in the output stream??
Checking the compressed file size in the output stream shows that the compressionLevel is getting picked up and having an effect.
a modified version of your code, I now pass in the ziplevel as the first arg:
Output:#!/bin/perl -w use strict; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); #$VERSION = '1.30'; die "usage: $0 ziplevel zipfile.zip file [...]\n" if (scalar(@ARGV) < 3); my $zipCompressionLevel = shift(@ARGV); my $zipName = shift(@ARGV); my $zip = Archive::Zip->new(); foreach my $memberName (map { glob } @ARGV){ my $member = $zip->addFile( $memberName ) or warn "Can't add file $memberName\n"; $member->desiredCompressionMethod( COMPRESSION_DEFLATED ); my $pre = $member->desiredCompressionLevel(); my $mid = $member->desiredCompressionLevel( $zipCompressionLevel ) +; my $end = $member->desiredCompressionLevel( ); print "Compression level:\n\tbefore: $pre, middle: $mid, after: $e +nd\n"; #print "compressed_size: " . $member->compressedSize() . "\n"; #print "uncompressed_size: " . $member->uncompressedSize() . "\n"; ### these are the same, since the file isn't actually compressed u +ntil writing. } my $status = $zip->writeToFileNamed($zipName); my $zipread = Archive::Zip->new(); $zipread->read( $zipName ); foreach my $member ($zipread->members()){ print $member->fileName()."\t", $member->compressionMethod()."\t", $member->desiredCompressionMethod()."\t", $member->desiredCompressionLevel(). "\n"; print " compressed_size: " . $member->compressedSize() . "\n"; print " uncompressed_size: " . $member->uncompressedSize() . "\n" +; } exit $status
$ perl ziptest.pl 9 zip.zip ziptest.pl Comptession level: before: -1, middle: -1, after: 9 ziptest.pl 8 8 -1 compressed_size: 576 uncompressed_size: 1449 $ perl ziptest.pl 1 zip.zip ziptest.pl Comptession level: before: -1, middle: -1, after: 1 ziptest.pl 8 8 -1 compressed_size: 608 uncompressed_size: 1449 $ perl ziptest.pl 0 zip.zip ziptest.pl Comptession level: before: -1, middle: -1, after: 0 ziptest.pl 8 8 -1 compressed_size: 1449 uncompressed_size: 1449
In reply to Re: Archive::Zip not honoring desiredCompressionMethod
by spazm
in thread Archive::Zip not honoring desiredCompressionMethod
by msalerno
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |