use strict;
use Archive::Zip;
use IO::File;
die "usage: $0 sfxname file [...]\n" unless @ARGV > 1;
my $outputName = shift();
my $zip = Archive::Zip->new();
foreach my $file (@ARGV)
{
$zip->addFileOrDirectory($file);
}
my $fh = IO::File->new( $outputName, O_CREAT | O_WRONLY | O_TRUNC, 0777 )
or die "Can't open $outputName\: $!\n";
binmode($fh);
while (<DATA>)
{
$fh->print($_)
}
$zip->writeToFileHandle($fh);
$fh->close();
__DATA__
use Archive::Zip qw(:ERROR_CODES);
use IO::File;
use File::Spec;
my $dir = 'extracted';
my $zip = Archive::Zip->new();
my $fh = IO::File->new($0) or die "Can't open $0\: $!\n";
die "Zip read error\n" unless $zip->readFromFileHandle($fh) == AZ_OK;
(mkdir($dir, 0777) or die "Can't create directory $dir\: $!\n") unless -d $dir;
for my $member ( $zip->members )
{
$member->extractToFileNamed( File::Spec->catfile($dir,$member->fileName) );
}
__DATA__