Debian lenny version packages
[pkg-perl] / deb-src / libarchive-zip-perl / libarchive-zip-perl-1.18 / examples / calcSizes.pl
1 # Example of how to compute compressed sizes
2 # $Revision: 1.2 $
3 use strict;
4 use Archive::Zip qw(:ERROR_CODES);
5 use File::Spec;
6 my $zip = Archive::Zip->new();
7 my $blackHoleDevice = File::Spec->devnull();
8
9 $zip->addFile($_) foreach (<*.pl>);
10
11 # Write and throw the data away.
12 # after members are written, the writeOffset will be set
13 # to the compressed size.
14 $zip->writeToFileNamed($blackHoleDevice);
15
16 my $totalSize = 0;
17 my $totalCompressedSize = 0;
18 foreach my $member ($zip->members())
19 {
20         $totalSize += $member->uncompressedSize;
21         $totalCompressedSize += $member->_writeOffset;
22         print "Member ", $member->externalFileName,
23         " size=", $member->uncompressedSize,
24         ", writeOffset=", $member->_writeOffset,
25         ", compressed=", $member->compressedSize,
26         "\n";
27 }
28
29 print "Total Size=", $totalSize, ", total compressed=", $totalCompressedSize, "\n";
30
31 $zip->writeToFileNamed('test.zip');