Archive Zip Compression Level

TedH's Avatar, Join Date: Apr 2012
Newbie Member
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
0
0
TedH's Avatar, Join Date: Apr 2012
Newbie Member
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
0
peterB's Avatar
Newbie Member
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();
0
TedH's Avatar, Join Date: Apr 2012
Newbie Member
I'd forgotten all about this...
Thanks, I'll give that a try.
0
peterB's Avatar
Newbie Member
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. :-)