Compress-Bzip2
view release on metacpan or search on metacpan
t/082-stream.t view on Meta::CPAN
# -*- mode: perl -*-
##
## this is the 03stream.t test from Compress::Bzip2 1.03 with no changes
## (except for comments)
##
## - seems to run a lot slower than the 1.03 test, probably because the add
## routine is now perl, not perlxs.
##
# streaming test
use strict;
use Test::More tests => 208;
use Compress::Bzip2 qw(compress_init decompress_init decompress);
# globals
my $Level = 1;
my @AlNum = ('A'..'Z','a'..'z','0'..'9',' ');
my ($In,$Out) = (0,0);
my $Prefix = 0;
# subs
sub try {
my ($str,$chunk,$inc) = @_;
$chunk ||= 100;
$inc ||= 0;
my $stream = compress_init();
# piece it into chunks and feed it to the monster
my ($size,$pos,$out,$done,$status,$orig) = ($chunk,0,'');
for(;;) {
if($pos > length $str) {
$status = $stream->finish();
$done = 1;
} else {
my $piece = substr $str,$pos,$size;
$pos += $size;
$size += $inc;
$status = $stream->add($piece);
}
return 0 if not defined $status;
$out .= $status;
last if $done;
}
# see if we can get it back
if($Prefix) {
$orig = decompress($stream->prefix().$out);
} else {
$stream = decompress_init();
($size,$pos,$orig,$done) = ($chunk,0,'');
for(;;) {
if($pos > length $out) {
$status = $stream->finish();
$done = 1;
} else {
my $piece = substr $out,$pos,$size;
$pos += $size;
$size += $inc;
$status = $stream->add($piece);
}
return 0 if not defined $status;
$orig .= $status;
last if $done;
( run in 1.941 second using v1.01-cache-2.11-cpan-39bf76dae61 )