Commit | Line | Data |
319fab50 |
1 | package IO::Uncompress::Adapter::Bunzip2; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use bytes; |
6 | |
dc82791d |
7 | use IO::Compress::Base::Common 2.017 qw(:Status); |
319fab50 |
8 | |
9 | #use Compress::Bzip2 ; |
dc82791d |
10 | use Compress::Raw::Bzip2 2.017 ; |
319fab50 |
11 | |
12 | our ($VERSION, @ISA); |
dc82791d |
13 | $VERSION = '2.017'; |
319fab50 |
14 | |
15 | #@ISA = qw( Compress::Raw::Bunzip2 ); |
16 | |
17 | |
18 | sub mkUncompObject |
19 | { |
20 | my $small = shift || 0; |
21 | my $verbosity = shift || 0; |
22 | |
23 | #my ($inflate, $status) = bzinflateInit; |
24 | #Small => $params->value('Small'); |
25 | my ($inflate, $status) = new Compress::Raw::Bunzip2(1, 1, $small, $verbosity); |
26 | |
27 | return (undef, "Could not create Inflation object: $status", $status) |
28 | if $status != BZ_OK ; |
29 | |
30 | return bless {'Inf' => $inflate, |
31 | 'CompSize' => 0, |
32 | 'UnCompSize' => 0, |
33 | 'Error' => '', |
34 | } ; |
35 | |
36 | } |
37 | |
38 | sub uncompr |
39 | { |
40 | my $self = shift ; |
41 | my $from = shift ; |
42 | my $to = shift ; |
43 | my $eof = shift ; |
44 | |
45 | my $inf = $self->{Inf}; |
46 | |
47 | my $status = $inf->bzinflate($from, $to); |
48 | $self->{ErrorNo} = $status; |
49 | |
50 | if ($status != BZ_STREAM_END && $eof) |
51 | { |
52 | $self->{Error} = "unexpected end of file"; |
53 | return STATUS_ERROR; |
54 | } |
55 | |
56 | if ($status != BZ_OK && $status != BZ_STREAM_END ) |
57 | { |
58 | $self->{Error} = "Inflation Error: $status"; |
59 | return STATUS_ERROR; |
60 | } |
61 | |
62 | |
63 | return STATUS_OK if $status == BZ_OK ; |
64 | return STATUS_ENDSTREAM if $status == BZ_STREAM_END ; |
65 | return STATUS_ERROR ; |
66 | } |
67 | |
68 | |
69 | #sub uncompr |
70 | #{ |
71 | # my $self = shift ; |
72 | # |
73 | # my $inf = $self->{Inf}; |
74 | # my $eof = $_[2]; |
75 | # |
76 | # #my ($out, $status) = $inf->bzinflate(${ $_[0] }); |
77 | # my $status = $inf->bzinflate($_[0], $_[1]); |
78 | # $self->{ErrorNo} = $status; |
79 | # |
80 | # if (! defined $out) |
81 | # { |
82 | # my $err = $inf->error(); |
83 | # $self->{Error} = "Inflation Error: $err"; |
84 | # return STATUS_ERROR; |
85 | # } |
86 | # |
87 | # #${ $_[1] } .= $out if defined $out; |
88 | # |
89 | # if ($eof) |
90 | # { |
91 | # #my ($out, $status) = $inf->bzclose(); |
92 | # $status = $inf->bzclose($_[1]); |
93 | # $self->{ErrorNo} = $status; |
94 | # |
95 | # if (! defined $out) |
96 | # { |
97 | # my $err = $inf->error(); |
98 | # $self->{Error} = "Inflation Error: $err"; |
99 | # return STATUS_ERROR; |
100 | # } |
101 | # |
102 | # #${ $_[1] } .= $out if defined $out; |
103 | # return STATUS_ENDSTREAM ; |
104 | # } |
105 | # |
106 | # return STATUS_OK ; |
107 | #} |
108 | |
109 | #sub uncompr |
110 | #{ |
111 | # my $self = shift ; |
112 | # |
113 | # my $inf = $self->{Inf}; |
114 | # my $eof = $_[2]; |
115 | # |
116 | # my ($out, $status) = $inf->bzinflate(${ $_[0] }); |
117 | # $self->{ErrorNo} = $status; |
118 | # |
119 | # if ($status != BZ_STREAM_END && $eof) |
120 | # { |
121 | # $self->{Error} = "unexpected end of file"; |
122 | # return STATUS_ERROR; |
123 | # } |
124 | # |
125 | # if ($status != BZ_OK && $status != BZ_STREAM_END ) |
126 | # { |
127 | # my $err = $inf->error(); |
128 | # $self->{Error} = "Inflation Error: $err"; |
129 | # return STATUS_ERROR; |
130 | # } |
131 | # |
132 | # ${ $_[1] } .= $out ; |
133 | # |
134 | # return STATUS_OK if $status == BZ_OK ; |
135 | # return STATUS_ENDSTREAM if $status == BZ_STREAM_END ; |
136 | # return STATUS_ERROR ; |
137 | #} |
138 | |
139 | sub reset |
140 | { |
141 | my $self = shift ; |
142 | |
143 | my ($inf, $status) = new Compress::Raw::Bunzip2(); |
144 | $self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ; |
145 | |
146 | if ($status != BZ_OK) |
147 | { |
148 | $self->{Error} = "Cannot create Inflate object: $status"; |
149 | return STATUS_ERROR; |
150 | } |
151 | |
152 | $self->{Inf} = $inf; |
153 | |
154 | return STATUS_OK ; |
155 | } |
156 | |
157 | #sub count |
158 | #{ |
159 | # my $self = shift ; |
160 | # $self->{Inf}->inflateCount(); |
161 | #} |
162 | |
163 | sub compressedBytes |
164 | { |
165 | my $self = shift ; |
166 | $self->{Inf}->compressedBytes(); |
167 | } |
168 | |
169 | sub uncompressedBytes |
170 | { |
171 | my $self = shift ; |
172 | $self->{Inf}->uncompressedBytes(); |
173 | } |
174 | |
175 | sub crc32 |
176 | { |
177 | my $self = shift ; |
178 | #$self->{Inf}->crc32(); |
179 | } |
180 | |
181 | sub adler32 |
182 | { |
183 | my $self = shift ; |
184 | #$self->{Inf}->adler32(); |
185 | } |
186 | |
187 | sub sync |
188 | { |
189 | my $self = shift ; |
190 | #( $self->{Inf}->inflateSync(@_) == BZ_OK) |
191 | # ? STATUS_OK |
192 | # : STATUS_ERROR ; |
193 | } |
194 | |
195 | |
196 | 1; |
197 | |
198 | __END__ |
199 | |