1package IO::Uncompress::Adapter::Inflate;
2
3use strict;
4use warnings;
5use bytes;
6
7use IO::Compress::Base::Common  2.084 qw(:Status);
8use Compress::Raw::Zlib  2.084 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS);
9
10our ($VERSION);
11$VERSION = '2.084';
12
13
14
15sub mkUncompObject
16{
17    my $crc32   = shift || 1;
18    my $adler32 = shift || 1;
19    my $scan    = shift || 0;
20
21    my $inflate ;
22    my $status ;
23
24    if ($scan)
25    {
26        ($inflate, $status) = new Compress::Raw::Zlib::InflateScan
27                                    #LimitOutput  => 1,
28                                    CRC32        => $crc32,
29                                    ADLER32      => $adler32,
30                                    WindowBits   => - MAX_WBITS ;
31    }
32    else
33    {
34        ($inflate, $status) = new Compress::Raw::Zlib::Inflate
35                                    AppendOutput => 1,
36                                    LimitOutput  => 1,
37                                    CRC32        => $crc32,
38                                    ADLER32      => $adler32,
39                                    WindowBits   => - MAX_WBITS ;
40    }
41
42    return (undef, "Could not create Inflation object: $status", $status)
43        if $status != Z_OK ;
44
45    return bless {'Inf'        => $inflate,
46                  'CompSize'   => 0,
47                  'UnCompSize' => 0,
48                  'Error'      => '',
49                  'ConsumesInput' => 1,
50                 } ;
51
52}
53
54sub uncompr
55{
56    my $self = shift ;
57    my $from = shift ;
58    my $to   = shift ;
59    my $eof  = shift ;
60
61    my $inf   = $self->{Inf};
62
63    my $status = $inf->inflate($from, $to, $eof);
64    $self->{ErrorNo} = $status;
65    if ($status != Z_OK && $status != Z_STREAM_END && $status != Z_BUF_ERROR)
66    {
67        $self->{Error} = "Inflation Error: $status";
68        return STATUS_ERROR;
69    }
70
71    return STATUS_OK        if $status == Z_BUF_ERROR ; # ???
72    return STATUS_OK        if $status == Z_OK ;
73    return STATUS_ENDSTREAM if $status == Z_STREAM_END ;
74    return STATUS_ERROR ;
75}
76
77sub reset
78{
79    my $self = shift ;
80    $self->{Inf}->inflateReset();
81
82    return STATUS_OK ;
83}
84
85#sub count
86#{
87#    my $self = shift ;
88#    $self->{Inf}->inflateCount();
89#}
90
91sub crc32
92{
93    my $self = shift ;
94    $self->{Inf}->crc32();
95}
96
97sub compressedBytes
98{
99    my $self = shift ;
100    $self->{Inf}->compressedBytes();
101}
102
103sub uncompressedBytes
104{
105    my $self = shift ;
106    $self->{Inf}->uncompressedBytes();
107}
108
109sub adler32
110{
111    my $self = shift ;
112    $self->{Inf}->adler32();
113}
114
115sub sync
116{
117    my $self = shift ;
118    ( $self->{Inf}->inflateSync(@_) == Z_OK)
119            ? STATUS_OK
120            : STATUS_ERROR ;
121}
122
123
124sub getLastBlockOffset
125{
126    my $self = shift ;
127    $self->{Inf}->getLastBlockOffset();
128}
129
130sub getEndOffset
131{
132    my $self = shift ;
133    $self->{Inf}->getEndOffset();
134}
135
136sub resetLastBlockByte
137{
138    my $self = shift ;
139    $self->{Inf}->resetLastBlockByte(@_);
140}
141
142sub createDeflateStream
143{
144    my $self = shift ;
145    my $deflate = $self->{Inf}->createDeflateStream(@_);
146    return bless {'Def'        => $deflate,
147                  'CompSize'   => 0,
148                  'UnCompSize' => 0,
149                  'Error'      => '',
150                 }, 'IO::Compress::Adapter::Deflate';
151}
152
1531;
154
155
156__END__
157
158