Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Howdy bros. I'm trying to set up some code using Archive::Zip to zip up a directory. I'm a little confused from the docs about how the compression level works. The directory in question has some zip files already in it, and I don't want to take the time to compress those since it won't do any good, but everything else I want to compress. So I've got this so far:
use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use File::Find qw(find); my $startdir = 'foo'; our $zip = Archive::Zip->new(); my $dir_member = $zip->addDirectory( '04campaigndashboard/' ); $dir_member->desiredCompressionLevel( 9 ); find(\&wanted,$startdir); sub wanted { ($fn = $File::Find::name) =~ s/$startdir//; if ($fn =~ /.zip/) { ???? } else { my $file_member = $zip->addFile( $fn ); } return; }
What I'm confused about is what goes in the zip case. The docs say you can change the compression for any element with the desiredCompressionLevel method, but you have to know the member name first. But isn't the file member compressed when you add it? If so this would not help me avoid the cycles to compress it only to uncompress it with the desiredCompressionLevel method, in fact it would make things worse.

Or is the compression done when the archive is written to disk?

UPDATE: I was just doing some testing and found tat the addFile method seems to not work when the argument is a zip file--it returns undef. So maybe you can't nest zip files with this mod at all>

TIA....Steve


In reply to Archive::Zip changing compression on the fly by cormanaz

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found