msalerno,

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:

#!/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
Output:
$ 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.