Skip to content

nextStream not updating filehandle correctly #3

Closed
@veryrusty

Description

@veryrusty

We are using IO::Uncompress::Unzip to iterate through zip files for various processes. We initially look for a specific filename (case-insensitive match). The files in the archive are CSV.

We've hit a case where the filehandle doesn't seem to be "positioned" correctly when nextStream is called. In the attached sample.zip, the first file in the archive has one line. The code below is attempting to dump the content of the second file (metadata.csv) in the archive.

Sample code:

#!/usr/bin/env perl
use strict;
use warnings;

use IO::Uncompress::Unzip;
use Data::Dumper;

my $file = 'sample.zip';
my $unzip = IO::Uncompress::Unzip->new($file) or die "Couldn't open ZIP\n";

do {{
    my $header   = $unzip->getHeaderInfo or die "Couldn't read ZIP";
    if ( $header->{Name} =~ m/^(metadata)\.csv$/i ) {
        my @content = <$unzip>;
        warn Dumper \@content;
    }
}} while ($unzip->nextStream > 0);

Sample input:
sample.zip

Script output:

$VAR1 = [
          '"organisation_path","collection_occasion_key","episode_key"
',
          '"key","value"
',
          '"version","2"
',
          '"type","PMHC"
'
        ];

where the first line is from the first file in the archive, not the file we are slurping content from, which is incorrect.

If the content of both files are read, the output is as expected. The single line of the first file that seems to cause issues.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingunzipIssues regarding unzip

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions