Reputation: 51
As part of a Perl script I am trying to read component from within a zip folder without uncompressing them. After some research I started trying to use Archive::Zip::MemberRead and after creating a test.zip that contained a test folder with 2 text fields it seemed to work fine. The issue I'm facing is the zip file I actually need to parse contents of just has all the .txt,.dat,.csv's in the zip with no sub-directory which seems to be causing issues. test.zip contains about 30 different zipped files including node_info.txt and I've been using the below code which worked when there was a sub-directory in the zip folder.
my $zip = Archive::Zip->new("C:\\test.zip");
my $fh = Archive::Zip::MemberRead->new($zip,'node_info.txt');
while (defined(my $line = $fh->getline()))
{
print $line . "\n";
}
When I try to run it though it errors Can't call method "readChunk" on an undefined value at C:/Perl/lib/Archive/Zip/MemberRead.pm line 268. Is there something different I need to do when passing the specific member to be read?
Upvotes: 1
Views: 3840
Reputation: 123639
I would suggest that there is no 'node_info.txt' in the specified zip file. At least that's exactly the error message I get if I try to access a non-existing entry. Please note, that the names in the Zip file are probably case sensitive, contrary to the way they are in windows file system.
It might be really helpful to add some error checking, e.g. check that $zip is true (Zip file could be opened) and $fh is true (entry exists in Zip file).
Upvotes: 0