{
my ($x, $output, $err, $in) =('', '', '', '') ;
if (ref $_[0] ) {
$in = $_[0] ;
croak "not a scalar reference" unless ref $in eq 'SCALAR' ;
}
else {
$in = \$_[0] ;
}
$] >= 5.008 and (utf8::downgrade($$in, 1)
or croak "Wide character in compress");
my $level = (@_ == 2 ? $_[1] : Z_DEFAULT_COMPRESSION() );
$x = new Compress::Raw::Zlib::Deflate -AppendOutput => 1, -Level => $level
or return undef ;
$err = $x->deflate($in, $output) ;
return undef unless $err == Z_OK() ;
$err = $x->flush($output) ;
return undef unless $err == Z_OK() ;
return $output ;
}
sub uncompress($)
{
my ($x, $output, $err, $in) =('', '', '', '') ;
if (ref $_[0] ) {
$in = $_[0] ;
croak "not a scalar reference" unless ref $in eq 'SCALAR' ;
}
else {
$in = \$_[0] ;
}
$] >= 5.008 and (utf8::downgrade($$in, 1)
or croak "Wide character in uncompress");
$x = new Compress::Raw::Zlib::Inflate -ConsumeInput => 0 or return undef ;
$err = $x->inflate($in, $output) ;
return undef unless $err == Z_STREAM_END() ;
return $output ;
}
sub deflateInit(@)
{
my ($got) = ParseParameters(0,
{
'Bufsize' => [1, 1, Parse_unsigned, 4096],
'Level' => [1, 1, Parse_signed, Z_DEFAULT_COMPRESSION()],
'Method' => [1, 1, Parse_unsigned, Z_DEFLATED()],
'WindowBits' => [1, 1, Parse_signed, MAX_WBITS()],
'MemLevel' => [1, 1, Parse_unsigned, MAX_MEM_LEVEL()],
'Strategy' => [1, 1, Parse_unsigned, Z_DEFAULT_STRATEGY()],
'Dictionary' => [1, 1, Parse_any, ""],
}, @_ ) ;
croak "Compress::Zlib::deflateInit: Bufsize must be >= 1, you specified " .
$got->value('Bufsize')
unless $got->value('Bufsize') >= 1;
my $obj ;
my $status = 0 ;
($obj, $status) =
Compress::Raw::Zlib::_deflateInit(0,
$got->value('Level'),
$got->value('Method'),
$got->value('WindowBits'),
$got->value('MemLevel'),
$got->value('Strategy'),
$got->value('Bufsize'),
$got->value('Dictionary')) ;
my $x = ($status == Z_OK() ? bless $obj, "Zlib::OldDeflate" : undef) ;
return wantarray ? ($x, $status) : $x ;
}
sub inflateInit(@)
{
my ($got) = ParseParameters(0,
{
'Bufsize' => [1, 1, Parse_unsigned, 4096],
'WindowBits' => [1, 1, Parse_signed, MAX_WBITS()],
'Dictionary' => [1, 1, Parse_any, ""],
}, @_) ;
croak "Compress::Zlib::inflateInit: Bufsize must be >= 1, you specified " .
$got->value('Bufsize')
=4= |