in reply to Uncompressing winzip downloaded in memory
Hello ganeshPerlStarter,
The IO::Uncompress::Unzip::unzip function also accepts a reference to a string for the input:
#! perl use strict; use warnings; use IO::Uncompress::Unzip qw(unzip $UnzipError) ; my $file = 'data.zip'; open(my $fh, '<', $file) or die "Cannot open file '$file' for reading: $!"; binmode $fh; my $input; { local $/ = undef; $input = <$fh>; } close $fh or die "Cannot close file '$file': $!"; my $output; my $status = unzip \$input => \$output or die "Unzip failed: $UnzipError\n"; print "Status: $status\n"; print "Unzipped text:\n\n>>>$output<<<\n";
I created a text file named “data.txt” and zipped it to “data.zip” using 7-Zip. The above script reads the zipped file data into the scalar $input, then correctly unzips it when passed a reference to the scalar (string) — \$input — as the input parameter.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Uncompressing winzip downloaded in memory
by ganeshPerlStarter (Novice) on Feb 04, 2015 at 05:59 UTC |