overload.pl shouldnt update its output unconditionally
[p5sagit/p5-mst-13.2.git] / ext / IO-Compress / lib / IO / Uncompress / Adapter / Inflate.pm
CommitLineData
a02d0f6f 1package IO::Uncompress::Adapter::Inflate;
1a6a8453 2
3use strict;
4use warnings;
a02d0f6f 5use bytes;
1a6a8453 6
80b215cb 7use IO::Compress::Base::Common 2.019 qw(:Status);
8use Compress::Raw::Zlib 2.019 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS);
1a6a8453 9
10our ($VERSION);
80b215cb 11$VERSION = '2.019';
1a6a8453 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 {
a02d0f6f 26 ($inflate, $status) = new Compress::Raw::Zlib::InflateScan
319fab50 27 #LimitOutput => 1,
1a6a8453 28 CRC32 => $crc32,
29 ADLER32 => $adler32,
30 WindowBits => - MAX_WBITS ;
31 }
32 else
33 {
a02d0f6f 34 ($inflate, $status) = new Compress::Raw::Zlib::Inflate
1a6a8453 35 AppendOutput => 1,
319fab50 36 LimitOutput => 1,
1a6a8453 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 } ;
50
51}
52
53sub uncompr
54{
55 my $self = shift ;
56 my $from = shift ;
57 my $to = shift ;
58 my $eof = shift ;
59
60 my $inf = $self->{Inf};
61
62 my $status = $inf->inflate($from, $to, $eof);
63 $self->{ErrorNo} = $status;
64
319fab50 65 if ($status != Z_OK && $status != Z_STREAM_END && $status != Z_BUF_ERROR)
1a6a8453 66 {
67 $self->{Error} = "Inflation Error: $status";
68 return STATUS_ERROR;
69 }
319fab50 70
71 return STATUS_OK if $status == Z_BUF_ERROR ; # ???
1a6a8453 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
a02d0f6f 85#sub count
86#{
87# my $self = shift ;
88# $self->{Inf}->inflateCount();
89#}
1a6a8453 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' => '',
a02d0f6f 150 }, 'IO::Compress::Adapter::Deflate';
1a6a8453 151}
152
1531;
154
155
156__END__
157