1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Archive Zip Compression Level

Discussion in 'Perl' started by TedH, Apr 11, 2012.

  1. TedH

    TedH New Member

    Joined:
    Apr 11, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Hi, I use Archive::Zip to zip up directories for my backups. This works fine, but I would like to have better cmpression rather than the deault 6.
    Code:
    ## works okay
    my $zip = Archive::Zip->new();
    $zip->addTree("path/to/directory");
    $zip->writeToFileNamed("holdzips/$drty.zip");
    
    
    ## I have tried this, but it errors 
    ## (Can't call method "desiredCompressionLevel"
    ##  without a package or object reference)
    my $zip = Archive::Zip->new();
    $zip->addTree("path/to/directory")->desiredCompressionLevel(9);
    $zip->writeToFileNamed("holdzips/$drty.zip");
    Hope someone can help please - Thanks
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
  3. TedH

    TedH New Member

    Joined:
    Apr 11, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Looked at that before, but it refers to an individual file. I'm zipping up a folder with files and sub folders in, some of those folder have sub folders.

    However, it does compress them to about half size (the default) so will settle for that.

    Thanks anyways
     
  4. peterB

    peterB New Member

    Joined:
    Nov 8, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    There is no obvious waym but the following works for me


    $zipHandle->addTree( $tmpDir, '' ); # adding a directory as tree

    # set compression level for each member of the zip file

    map { $_->desiredCompressionLevel( $compressionLevel ) } $zipHandle->members();
     
  5. TedH

    TedH New Member

    Joined:
    Apr 11, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    I'd forgotten all about this...
    Thanks, I'll give that a try.
     
  6. peterB

    peterB New Member

    Joined:
    Nov 8, 2012
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Well, I had the same problem as you and found your question when I was looking for an answer. :)

    So I thought I'd provide my solution in case another person follows our steps. :)
     

Share This Page