in reply to Reading data from ZIP data in a File::Temp filehandle problem

I added my $tmp = IO::File->new( 'test1.zip', 'r' ); straight from the Archive::Zip documentation for readFromFileHandle() at cpan to open a filehandle and it works. I tried first with open() and got an error from Archive::Zip that the file must be seekable. Then in the documentation it mentions it must be seekable. I didn't realize there was a difference.

use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use Data::Dumper; my $tmp = IO::File->new( 'test1.zip', 'r' ); my $zip = Archive::Zip->new(); my $zip_err = $zip->readFromFileHandle( $tmp ); 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); }

Replies are listed 'Best First'.
Re^2: Reading data from ZIP data in a File::Temp filehandle problem
by drewhead (Beadle) on Sep 15, 2011 at 12:51 UTC
    Yes, but I'm not starting with a file, I'm starting with an URL and staging the file temporarily via File::Temp. The pod documentation of File::Temp specifically states:
    Filehandles returned by these functions support the seekable methods.
    I don't understand why I would necessarily need to know what the file being created on the fly specifically is if I can just pass a filehandle around and make Archive::Zip read data from the filehandle. Clearly I now see that this differs from how Archive::Zip works. And I do see the documentation that states that is does not yet support streams. I was hoping not to have code that needed to be aware of a temporary file given that such a file was already an open filehandle. It looks like readFromFileHandle() is really only a way to save one an extra file open operation given a file was previously opened?

      The way to troubleshoot this is to verify all the parts work individually and then put them together. The next thing to verify is that if the temporary file handle contains a valid zip file that readFromFileHandle will read it. I have experience with Archive::Zip not temporary files. If someone could show how to copy a zip file from disk to a temporary file then you could use that for testing.