IO-Compress

 view release on metacpan or  search on metacpan

t/011-streamzip.t  view on Meta::CPAN


{
    title "streamzip" ;

    my ($infile, $outfile);
    my $lex = LexFile->new( $infile, $outfile );

    writeFile($infile, $hello1) ;
    check "$Perl ${binDir}/streamzip <$infile >$outfile";

    my $uncompressed ;
    unzip $outfile => \$uncompressed;
    is $uncompressed, $hello1;
}

{
    title "streamzip - zipfile option" ;

    my ($infile, $outfile);
    my $lex = LexFile->new( $infile, $outfile );

    writeFile($infile, $hello1) ;
    check "$Perl ${binDir}/streamzip -zipfile $outfile <$infile";

    my $uncompressed ;
    unzip $outfile => \$uncompressed;
    is $uncompressed, $hello1;
}

for my $method (qw(store deflate bzip2 lzma xz zstd))
{
    SKIP:
    {
        if ($method eq 'lzma')
        {
            no warnings;
            eval { require IO::Compress::Lzma && defined &{ 'IO::Compress::Adapter::Bzip2::mkRawZipCompObject' } } ;
            skip "Method 'lzma' needs IO::Compress::Lzma\n", 8
                if $@;
        }

        if ($method eq 'zstd')
        {
            no warnings;
            eval { require IO::Compress::Zstd && defined &{ 'IO::Compress::Adapter::Zstd::mkRawZipCompObject' }} ;
            skip "Method 'zstd' needs IO::Compress::Zstd\n", 8
                if $@;
        }

        if ($method eq 'xz')
        {
            no warnings;
            eval { require IO::Compress::Xz && defined &{ 'IO::Compress::Adapter::Xz::mkRawZipCompObject' }} ;
            skip "Method 'xz' needs IO::Compress::Xz\n", 8
                if $@;
        }

        {
            title "streamzip method $method" ;

            skip "streaming unzip not supported with zstd\n", 7
                if $method eq 'zstd' ;

            my ($infile, $outfile);
            my $lex = LexFile->new( $infile, $outfile );

            writeFile($infile, $hello1) ;
            check "$Perl ${binDir}/streamzip -method $method <$infile >$outfile";

            my $uncompressed ;
            unzip $outfile => \$uncompressed;
            is $uncompressed, $hello1;
        }

        {
            title "streamzip $method- zipfile option" ;

            my ($infile, $outfile);
            my $lex = LexFile->new( $infile, $outfile );

            writeFile($infile, $hello1) ;
            check "$Perl ${binDir}/streamzip -zipfile $outfile -method $method <$infile";

            my $uncompressed ;
            unzip $outfile => \$uncompressed;
            is $uncompressed, $hello1;
        }
    }
}

for my $level (0 ..9)
{
    {
        title "streamzip level $level" ;

        my ($infile, $outfile);
        my $lex = LexFile->new( $infile, $outfile );

        writeFile($infile, $hello1) ;
        check "$Perl ${binDir}/streamzip -$level <$infile >$outfile";

        my $uncompressed ;
        unzip $outfile => \$uncompressed;
        is $uncompressed, $hello1;
    }

    {
        title "streamzip level $level- zipfile option" ;

        my ($infile, $outfile);
        my $lex = LexFile->new( $infile, $outfile );

        writeFile($infile, $hello1) ;
        check "$Perl ${binDir}/streamzip -zipfile $outfile -$level <$infile";

        my $uncompressed ;
        unzip $outfile => \$uncompressed;
        is $uncompressed, $hello1;
    }

}



( run in 3.127 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )