1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
# -*- cperl -*-
# -----------------------------------------------------------------------------
# $Id: Zlib.pm 3004 2007-12-10 12:45:39Z topia $
# -----------------------------------------------------------------------------
# copyright (C) 2003 Topia <topia@clovery.jp>. all rights reserved.
package System::Inflate::Zlib;
use strict;
use warnings;
use Carp;
use Compress::Zlib;
sub new {
my ($class) = @_;
my $obj =
{
Z_OK => Compress::Zlib::Z_OK(),
Z_STREAM_END => Compress::Zlib::Z_STREAM_END(),
Z_DATA_ERROR => Compress::Zlib::Z_DATA_ERROR(),
accept => 'inflate'
};
bless $obj,$class;
return $obj;
}
sub setup {
my ($this, $parent) = @_;
foreach my $compressor qw(inflate) {
$parent->{compressor}->{$compressor} = $this;
$this->{parent} = $parent;
}
return $parent;
}
sub parent {
return shift->{parent};
}
sub init {
my ($this, $datas, $data_chunk) = @_;
($datas->{stream}, $datas->{lasterr}) =
Compress::Zlib::inflateInit(-WindowBits => - Compress::Zlib::MAX_WBITS());
return undef if $datas->{lasterr} != $this->{Z_OK};
return $this->parent->COMP_OK if $datas->{lasterr} == $this->{Z_OK};
return $this->parent->COMP_OTHER_ERR;
}
sub inflate {
my ($this, $datas, $data_chunk) = @_;
my ($ret);
carp('not initialized!') if !defined $datas->{stream};
($ret, $datas->{lasterr}) = $datas->{stream}->inflate($data_chunk);
$datas->{stream} = undef if $datas->{lasterr} != $this->{Z_OK};
return ($ret, $this->parent->COMP_OK) if $datas->{lasterr} == $this->{Z_OK};
return ($ret, $this->parent->COMP_STREAM_END) if $datas->{lasterr} == $this->{Z_STREAM_END};
return (undef, $this->parent->COMP_OTHER_ERR);
}
sub check {
my ($this, $datas) = @_;
return 1;
}
sub final {
my ($this) = @_;
return $this->parent->COMP_OK;
}
1;
|