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().


In reply to Re^3: Reading data from ZIP data in a File::Temp filehandle problem by Corion
in thread Reading data from ZIP data in a File::Temp filehandle problem by drewhead

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.