IO-Compress

 view release on metacpan or  search on metacpan

t/105oneshot-zip-only.t  view on Meta::CPAN


            my $u = IO::Uncompress::Unzip->new( $file1 )
                or diag $ZipError ;

            my $hdr = $u->getHeaderInfo();
            ok $hdr, "  got header";

            is $hdr->{Stream}, $stream, "  stream is $stream" ;
            is $hdr->{MethodID}, $method, "  MethodID is $method" ;
            is $hdr->{Zip64}, $zip64, "  Zip64 is $zip64" ;
        }
    }
}

for my $stream (0, 1)
{
    for my $zip64 (0, 1)
    {
        next if $zip64 && ! $stream;
        for my $method (ZIP_CM_STORE, ZIP_CM_DEFLATE)
        {
            title "Stream $stream, Zip64 $zip64, Method $method";

            my $file1;
            my $file2;
            my $zipfile;
            my $lex = LexFile->new( $file1, $file2, $zipfile );

            my $content1 = "hello ";
            writeFile($file1, $content1);

            my $content2 = "goodbye ";
            writeFile($file2, $content2);

            my %content = ( $file1 => $content1,
                            $file2 => $content2,
                          );

            ok zip([$file1, $file2] => $zipfile , Method => $method,
                                                  Zip64  => $zip64,
                                                  Stream => $stream), " zip ok"
                or diag $ZipError ;

            for my $file ($file1, $file2)
            {
                my $got ;
                ok unzip($zipfile => \$got, Name => $file), "  unzip $file ok"
                    or diag $UnzipError ;

                is $got, $content{$file}, "  content ok";
            }
        }
    }
}

my $ebcdic_skip_msg = "Input file is in an alien character set";

SKIP: {
    skip $ebcdic_skip_msg, 3 if ord "A" != 65;

    title "Regression: ods streaming issue";

    # To execute this test on a non-ASCII machine, we could open the zip file
    # without using the Name parameter, or xlate the parameter to ASCII, and
    # also xlate the contents to native.

    # The file before meta.xml in test.ods is content.xml.
    # Issue was triggered because content.xml was stored
    # as streamed and the code to walk the compressed streaming
    # content assumed that all of the input buffer was consumed
    # in a single call to "uncompr".

    my $files = "./t/" ;
    $files = "./" if $ENV{PERL_CORE} ;
    $files .= "files/";

    my $zipfile = "$files/test.ods" ;
    my $file = "meta.xml";

    my $got;

    ok unzip($zipfile => \$got, Name => $file), "  unzip $file ok"
        or diag $UnzipError ;

    my $meta = '<?xml version="1.0" encoding="UTF-8"?>
<office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http:/...

    is $got, $meta, "  content ok";

}

SKIP: {
    skip $ebcdic_skip_msg, 3 if ord "A" != 65;

    title "Regression: odt non-streaming issue";
    # https://github.com/pmqs/IO-Compress/issues/13

    # Some programs (LibreOffice) mark entries as Streamed (bit 3 of the General Purpose Bit Flags field is set) ,
    # but still fill out the Compressed Length, Uncompressed Length & CRC32 fields in the local file header

    my $files = "./t/" ;
    $files = "./" if $ENV{PERL_CORE} ;
    $files .= "files/";

    my $zipfile = "$files/testfile1.odt" ;
    my $file = "manifest.rdf";

    my $got;

    ok unzip($zipfile => \$got, Name => $file), "  unzip $file ok"
        or diag $UnzipError ;

    my $meta = <<'EOM';
<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
  <rdf:Description rdf:about="">
    <rdf:type rdf:resource="http://docs.oasis-open.org/ns/office/1.2/meta/pkg#Document"/>
  </rdf:Description>
</rdf:RDF>
EOM
    is $got, $meta, "  content ok";
}

# TODO add more error cases



( run in 0.741 second using v1.01-cache-2.11-cpan-5735350b133 )