3
# Shows one way to write a self-extracting archive file.
4
# This is not intended for production use, and it always extracts to a
5
# subdirectory with a fixed name.
6
# Plus, it requires Perl and A::Z to be installed first.
8
# In general, you want to provide a stub that is platform-specific.
9
# You can use 'unzipsfx' that it provided with the Info-Zip unzip program.
10
# Get this from http://www.info-zip.org .
19
# Make a self-extracting Zip file.
21
die "usage: $0 sfxname file [...]\n" unless @ARGV > 1;
23
my $outputName = shift();
25
my $zip = Archive::Zip->new();
27
foreach my $file (@ARGV)
29
$zip->addFileOrDirectory($file);
32
my $fh = IO::File->new( $outputName, O_CREAT | O_WRONLY | O_TRUNC, 0777 )
33
or die "Can't open $outputName\: $!\n";
36
# add self-extracting Perl code
43
$zip->writeToFileHandle($fh);
47
# below the __DATA__ line is the extraction stub:
50
# Self-extracting Zip file extraction stub
51
# Copyright (C) 2002 Ned Konz
53
use Archive::Zip qw(:ERROR_CODES);
57
my $dir = 'extracted';
58
my $zip = Archive::Zip->new();
59
my $fh = IO::File->new($0) or die "Can't open $0\: $!\n";
60
die "Zip read error\n" unless $zip->readFromFileHandle($fh) == AZ_OK;
62
(mkdir($dir, 0777) or die "Can't create directory $dir\: $!\n") unless -d $dir;
64
for my $member ( $zip->members )
66
$member->extractToFileNamed( File::Spec->catfile($dir,$member->fileName) );