use strict;
use LWP::UserAgent;
use Archive::Zip;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
use Data::Dumper;
my $url = 'http://keep.drewhead.org/test.zip';
my $file = '../test.zip'; # a local copy of $url
# This doesn't
{
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get($url);
warn length($response->decoded_content);
my $tmp;
if ($response->is_success) {
$tmp = File::Temp->new();
binmode $tmp;
print {$tmp} $response->decoded_content;
print "Wrote ".$tmp->filename()."\n";
}
else { die "error ".$response->status_line; }
#unless (-B $tmp) { die "Did not get a filehandle\n"; }
my $zip = Archive::Zip->new();
my $zip_err = $zip->readFromFileHandle( $tmp, $tmp->filename );
unless ($zip_err == AZ_OK ) {
die "Archive::Zip read error on filehandle: $zip_err\n";
}
foreach my $member ($zip->members()) {
my $fileName = $member->fileName();
print "fileName = $fileName\n";
my $content = $member->contents();
print "contents $fileName = ".Dumper($content);
}
}
I added the binmode call before writing the tempfile, and I pass the name of the tempfile down to ->readFromFileHandle(). |