Derek B. Smith wrote:

--- Tom Phoenix <[EMAIL PROTECTED]> wrote:

On 9/11/06, Derek B. Smith
<[EMAIL PROTECTED]> wrote:

I need to compress a bunch of files, so instead of making a system call to
gzip I figured to try out Archive::Zip. After running this code it creates a
new file but is larger in size.

That module automatically uses Compress::Zlib to compress the data. Were any
of the files compressed before you started? Compression algorithms can't
shrink every file, and files that have compact formats can't be shrunk. If you
try collecting the files with another archiving tool, you should see roughly
the same results, if they're already compact: The archive will be roughly the
same size as the uncompressed data, or a little larger.

Cheers!

--Tom Phoenix


**********************
Thank you 4 replying!.
The files attributes prior to using gzip were:
-rw-r--r--   1 root       sys        9007879 Sep 11
15:24 derek.log

after compression using gzip are:
-rw-r--r--   1 root       sys         393013 Sep 11
15:24 derek.log.gz

as you can see this file was compressed significantly
as it is a large text based file:
#>file derek.log
derek.log:      ascii text

Is this code syntactically correct to produce a zipped
file ?  I read the POD and there are no clear
examples. Please help...thank you
derek


#!/usr/bin/perl

use strict;
use warnings;
use diagnostics;
use Data::Dumper;
use Readonly;
use Archive::Zip qw ( :ERROR_CODES :CONSTANTS );

my $zip = Archive::Zip->new();

# add all readable files and directories
  $zip->addTree( '/usr/local/admin', 'derek' );
  # and write them into a file
  $zip->writeToFileNamed('xxx.zip');

That looks fine to me Derek, but of course it depends on what you're trying to
do! What you have written will add (as your comment says) all readable files and
directories at or below /usr/local/admin. Check the resulting zip file to see if
it has stuff in it you didn't mean to archive.

I wonder if you just meant to zip derek.log? If so, then replace the addTree
method call with

 my $entry = $zip->addFile('/usr/local/admin/derek.log', 'derek.log') or die 
'Failed to add file';

and if you want the target file as small as possible (at the expense of a longer
compression time) then add:

 $entry->desiredCompressionLevel(9);

after the call to addFile and before writeToFileNamed.

HTH,

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to