Skip to content

IO::Uncompress::Unzip::getHeaderInfo() should provide (more) information in transparent mode #35

@tlhackque

Description

@tlhackque

While I'm reporting issues with IO::Uncompress::Unzip:

When processing files that may turn out not to be compressed, I try to have a common code path.

getHeaderInfo() simply returns undef. I use the following code, which really belongs in getHeaderInfo.

     my $member = $in->getHeaderInfo();
     if( !defined $member ) {
        my $size = ( stat $filename )[7] || 0;
        $size = U64->new( int( $size / U64::HI_1 ), int( $size % U64::HI_1 ) );
        $member = { Name               => $filename,
                  Time               => ( ( stat _ )[9] ) || 0,
                  Type               => $type,
                  UncompressedLength => $size,
                  MethodName         => 'uncompressed',
                };
    }

Providing this pseudo-header metadata allows the following code to use @member->{*} to report filename, size, time, etc. (If this looks odd, in real life it's a subroutine...and $type is 'text', or if binmode has been called, data)

Note that the code in Uncompress::Base sets Name to undef and Type to 'plain', expecting a caller of getHeaderInfo to receive that - even though getHeaderInfo in fact returns undef.

I'm not especially happy about using the U64 method, but that's what getHeaderInfo returns for compressed files.

Note that what's returned for compressed files is not well documented - it should be.

This method returns either a hash reference (in scalar context) or a
list or hash references (in array context) that contains information
about each of the header fields in the compressed data stream(s).

requires a dive into the internals to figure out how to turn "information about" into specific usable data.

And it would be nice if u64::new did the math to split a 64-bit int (or on 32-bit systems, double) into the required upper and lower 1/2s.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions