in reply to Re^2: Reading data from ZIP data in a File::Temp filehandle problem
in thread Reading data from ZIP data in a File::Temp filehandle problem
It seems that ->readFromFileHandle really wants the filename. The following works for me:
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().
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Reading data from ZIP data in a File::Temp filehandle problem
by drewhead (Beadle) on Sep 15, 2011 at 12:32 UTC |