summaryrefslogtreecommitdiff
path: root/examples/writeScalar2.pl
blob: dab44c5c8aaf5d43f2912feac1c715e91d82adb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/perl -w
use strict;
use Archive::Zip qw(:CONSTANTS :ERROR_CODES);
use IO::String;
use IO::File;

# test writing to a scalar
my $zipContents = '';
my $SH          = IO::String->new($zipContents);

my $zip = Archive::Zip->new();
my $member = $zip->addString('a' x 300, 'bunchOfAs.txt');
$member->desiredCompressionMethod(COMPRESSION_DEFLATED);
$member = $zip->addString('b' x 300, 'bunchOfBs.txt');
$member->desiredCompressionMethod(COMPRESSION_DEFLATED);
my $status = $zip->writeToFileHandle($SH);

my $file = IO::File->new('test.zip', 'w');
binmode($file);
$file->print($zipContents);
$file->close();