Blame examples/readScalar.pl
|
Packit |
0bf95d |
#!/usr/bin/perl -w
|
|
Packit |
0bf95d |
# Demonstrates reading a zip from an IO::Scalar
|
|
Packit |
0bf95d |
# $Revision: 1.4 $
|
|
Packit |
0bf95d |
use strict;
|
|
Packit |
0bf95d |
use Archive::Zip qw(:CONSTANTS :ERROR_CODES);
|
|
Packit |
0bf95d |
use IO::Scalar;
|
|
Packit |
0bf95d |
use IO::File;
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
# test reading from a scalar
|
|
Packit |
0bf95d |
my $file = IO::File->new('testin.zip', 'r');
|
|
Packit |
0bf95d |
my $zipContents;
|
|
Packit |
0bf95d |
binmode($file);
|
|
Packit |
0bf95d |
$file->read($zipContents, 20000);
|
|
Packit |
0bf95d |
$file->close();
|
|
Packit |
0bf95d |
printf "Read %d bytes\n", length($zipContents);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
my $SH = IO::Scalar->new(\$zipContents);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
my $zip = Archive::Zip->new();
|
|
Packit |
0bf95d |
$zip->readFromFileHandle($SH);
|
|
Packit |
0bf95d |
my $member = $zip->addString('c' x 300, 'bunchOfCs.txt');
|
|
Packit |
0bf95d |
$member->desiredCompressionMethod(COMPRESSION_DEFLATED);
|
|
Packit |
0bf95d |
$member = $zip->addString('d' x 300, 'bunchOfDs.txt');
|
|
Packit |
0bf95d |
$member->desiredCompressionMethod(COMPRESSION_DEFLATED);
|
|
Packit |
0bf95d |
|
|
Packit |
0bf95d |
$zip->writeToFileNamed('test2.zip');
|