blib/lib/IO/Uncompress/RawInflate.pm

filter: Statementstmt 99.2% 128 / 129 Branchbran 76.9% 40 / 52 Conditioncond 62.5% 15 / 24 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 100% 21 / 21 Podpod 25.0% 3 / 12 totaltotal 84.1% 213 / 253 CC 34 SCAR 17.9
CC
34
Cov
89%
inflateSync
10.3
_isRawx
10.0
scan
7.3
CRAP 6.0
« blib/lib/Compress/Zlib.pm ↑ Summary blib/lib/IO/Compress/Adapter/Bzip2.pm »
1 package IO::Uncompress::RawInflate ;
2 # for RFC1951
3  
4 96 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 96 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 96 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 96 ▶use Compress::Raw::Zlib 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 96 ▶use IO::Compress::Base::Common 2.225 qw(:Status );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 96 ▶use IO::Uncompress::Base 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 96 ▶use IO::Uncompress::Adapter::Inflate 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 96 require Exporter ;
15 96 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $RawInflateError);
16  
17 96 $VERSION = '2.225';
18 96 $RawInflateError = '';
19  
20 96 @ISA = qw(IO::Uncompress::Base Exporter);
21 96 @EXPORT_OK = qw( $RawInflateError rawinflate ) ;
22 96 %DEFLATE_CONSTANTS = ();
23 96 %EXPORT_TAGS = %IO::Uncompress::Base::EXPORT_TAGS ;
24 96 ▶$EXPORT_TAGS{all} = [ defined $EXPORT_TAGS{all} ? @{ $EXPORT_TAGS{all} } : (), @EXPORT_OK ] ;
Branch: 1 branch
BranchTrueFalseTotal
defined $IO::Uncompress::RawInflate::EXPORT_TAGS{'all'} ? : 96 0 96
25 96 Exporter::export_ok_tags('all');
26  
27 #{
28 # # Execute at runtime
29 # my %bad;
30 # for my $module (qw(Compress::Raw::Zlib IO::Compress::Base::Common IO::Uncompress::Base IO::Uncompress::Adapter::Inflate))
31 # {
32 # my $ver = ${ $module . "::VERSION"} ;
33 #
34 # $bad{$module} = $ver
35 # if $ver ne $VERSION;
36 # }
37 #
38 # if (keys %bad)
39 # {
40 # my $string = join "\n", map { "$_ $bad{$_}" } keys %bad;
41 # die caller(0)[0] . "needs version $VERSION mismatch\n$string\n";
42 # }
43 #}
44  
45 sub new
46 275 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
47 275 my $class = shift ;
48 275 my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$RawInflateError);
49 275 $obj->_create(undef, 0, @_);
50 }
51  
52 sub rawinflate
53 66 ▶{
Subroutine rawinflate: called CC=1 SCAR=0.0
Pod documented
54 66 my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$RawInflateError);
55 66 return $obj->_inf(@_);
56 }
57  
58 sub getExtraParams
59 324 ▶{
Subroutine getExtraParams: called CC=1 SCAR=0.0
Pod undocumented
60 324 return ();
61 }
62  
63 sub ckParams
64 332 ▶{
Subroutine ckParams: called CC=1 SCAR=0.0
Pod undocumented
65 332 my $self = shift ;
66 332 my $got = shift ;
67  
68 332 return 1;
69 }
70  
71 sub mkUncomp
72 1163 ▶{
Subroutine mkUncomp: called CC=4 SCAR=13.9
Pod undocumented
73 1163 my $self = shift ;
74 1163 my $got = shift ;
75  
76 1163 my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject(
77 $got->getValue('crc32'),
78 $got->getValue('adler32'),
79 $got->getValue('scan'),
80 );
81  
82 1163 ▶ return $self->saveErrorString(undef, $errstr, $errno)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $obj 0 1163 1163
83 if ! defined $obj;
84  
85 1163 *$self->{Uncomp} = $obj;
86  
87 1163 ▶ my $magic = $self->ckMagic()
Branch: 1 branch
BranchTrueFalseTotal
my $magic = $self->ckMagic or return 0 985 178 1163
88 or return 0;
89  
90 985 ▶ *$self->{Info} = $self->readHeader($magic)
Branch: 1 branch
BranchTrueFalseTotal
*$self->{"Info"} = $self->readHeader($magic) or return undef 958 27 985
91 or return undef ;
92  
93 958 return 1;
94  
95 }
96  
97  
98 sub ckMagic
99 2093 ▶{
Subroutine ckMagic: called CC=1 SCAR=0.0
Pod undocumented
100 2093 my $self = shift;
101  
102 2093 return $self->_isRaw() ;
103 }
104  
105 sub readHeader
106 884 ▶{
Subroutine readHeader: called CC=1 SCAR=0.0
Pod undocumented
107 884 my $self = shift;
108 884 my $magic = shift ;
109  
110 return {
111 884 'Type' => 'rfc1951',
112 'FingerprintLength' => 0,
113 'HeaderLength' => 0,
114 'TrailerLength' => 0,
115 'Header' => ''
116 };
117 }
118  
119 sub chkTrailer
120 4 ▶{
Subroutine chkTrailer: called CC=1 SCAR=0.0
Pod undocumented
121 4 return STATUS_OK ;
122 }
123  
124 sub _isRaw
125 2093 ▶{
Subroutine _isRaw: called CC=2 SCAR=6.9
126 2093 my $self = shift ;
127  
128 2093 my $got = $self->_isRawx(@_);
129  
130 2093 ▶ if ($got) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got) { } 884 1209 2093
131 884 *$self->{Pending} = *$self->{HeaderPending} ;
132 }
133 else {
134 1209 $self->pushBack(*$self->{HeaderPending});
135 1209 *$self->{Uncomp}->reset();
136 }
137 2093 *$self->{HeaderPending} = '';
138  
139 2093 return $got ;
140 }
141  
142 sub _isRawx
143 2093 ▶{
Subroutine _isRawx: called CC=10 SCAR=23.1
144 2093 my $self = shift ;
145 2093 my $magic = shift ;
146  
147 2093 ▶ $magic = '' unless defined $magic ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $magic 2093 0 2093
148  
149 2093 my $buffer = '';
150  
151 2093 ▶ $self->smartRead(\$buffer, *$self->{BlockSize}) >= 0
Branch: 1 branch
BranchTrueFalseTotal
$self->smartRead(\$buffer, *$self->{"BlockSize"}) >= 0 or return $self->saveErrorString(undef, "No data to read") 2093 0 2093
152 or return $self->saveErrorString(undef, "No data to read");
153  
154 2093 my $temp_buf = $magic . $buffer ;
155 2093 *$self->{HeaderPending} = $temp_buf ;
156 2093 $buffer = '';
157 2093 my $status = *$self->{Uncomp}->uncompr(\$temp_buf, \$buffer, $self->smartEof()) ;
158  
159 2093 ▶ return $self->saveErrorString(undef, *$self->{Uncomp}{Error}, STATUS_ERROR)
Branch: 1 branch
BranchTrueFalseTotal
if $status == -1 1172 921 2093
160 if $status == STATUS_ERROR;
161  
162 921 $self->pushBack($temp_buf) ;
163  
164 921 ▶ return $self->saveErrorString(undef, "unexpected end of file", STATUS_ERROR)
Branch: 1 branch
BranchTrueFalseTotal
if $self->smartEof and $status != 1 37 884 921
Condition100%3/3
$self->smartEof and $status != 1
!ll&&!rl&&r
35552937
MC/DC100%2/2
$self->smartEof and $status != 1
$self->smartEof $status != 1
Truth table100%3/3
A and B
A= $self->smartEofB= $status != 1
ABresult
0X0
100
111
165 if $self->smartEof() && $status != STATUS_ENDSTREAM;
166  
167 #my $buf_len = *$self->{Uncomp}->uncompressedBytes();
168 884 my $buf_len = length $buffer;
169  
170 884 ▶ if ($status == STATUS_ENDSTREAM) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 1) 876 8 884
171 876 ▶ if (*$self->{MultiStream}
Branch: 1 branch
BranchTrueFalseTotal
if (*$self->{'MultiStream'} and length $temp_buf || !$self->smartEof) { } 234 642 876
Condition83%5/6
*$self->{"MultiStream"} and length $temp_buf || !$self->smartEof
!ll&&!rl&&r
507135234
length $temp_buf or not $self->smartEof
l!l&&r!l&&!r
2340135
MC/DC66%2/3
*$self->{"MultiStream"} and length $temp_buf || !$self->smartEof
*$self->{"MultiStream"} length $temp_buf not $self->smartEof
Truth table75%3/4
A and B or not(C)
A= *$self->{"MultiStream"}B= length $temp_bufC= not $self->smartEof
ABCresult
0XX0
1000
11X1
1011
172 && (length $temp_buf || ! $self->smartEof())){
173 234 *$self->{NewStream} = 1 ;
174 234 *$self->{EndStream} = 0 ;
175 }
176 else {
177 642 *$self->{EndStream} = 1 ;
178 }
179 }
180 884 *$self->{HeaderPending} = $buffer ;
181 884 *$self->{InflatedBytesRead} = $buf_len ;
182 884 *$self->{TotalInflatedBytesRead} += $buf_len ;
183 884 *$self->{Type} = 'rfc1951';
184  
185 884 $self->saveStatus(STATUS_OK);
186  
187 return {
188 884 'Type' => 'rfc1951',
189 'HeaderLength' => 0,
190 'TrailerLength' => 0,
191 'Header' => ''
192 };
193 }
194  
195  
196 sub inflateSync
197 16 ▶{
Subroutine inflateSync: called CC=10 SCAR=23.3
Pod documented
198 16 my $self = shift ;
199  
200 # inflateSync is a no-op in Plain mode
201 return 1
202 16 ▶ if *$self->{Plain} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Plain"} 4 12 16
203  
204 12 ▶ return 0 if *$self->{Closed} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Closed"} 4 8 12
205 #return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ;
206 8 ▶ return 0 if ! length *$self->{Pending} && *$self->{EndStream} ;
Branch: 1 branch
BranchTrueFalseTotal
if not length *$self->{"Pending"} and *$self->{"EndStream"} 0 8 8
Condition33%1/3
not length *$self->{"Pending"} and *$self->{"EndStream"}
!ll&&!rl&&r
800
MC/DC0%0/2
not length *$self->{"Pending"} and *$self->{"EndStream"}
not length *$self->{"Pending"} *$self->{"EndStream"}
Truth table33%1/3
not(A) and B
A= not length *$self->{"Pending"}B= *$self->{"EndStream"}
ABresult
0X0
100
111
207  
208 # Disable CRC check
209 8 *$self->{Strict} = 0 ;
210  
211 8 my $status ;
212 8 while (1)
213 {
214 1188 my $temp_buf ;
215  
216 1188 ▶ if (length *$self->{Pending} )
Branch: 1 branch
BranchTrueFalseTotal
if (length *$self->{'Pending'}) { } 8 1180 1188
217 {
218 8 $temp_buf = *$self->{Pending} ;
219 8 *$self->{Pending} = '';
220 }
221 else
222 {
223 1180 $status = $self->smartRead(\$temp_buf, *$self->{BlockSize}) ;
224 1180 ▶ return $self->saveErrorString(0, "Error Reading Data")
Branch: 1 branch
BranchTrueFalseTotal
if $status < 0 0 1180 1180
225 if $status < 0 ;
226  
227 1180 ▶ if ($status == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 0) 4 1176 1180
228 4 *$self->{EndStream} = 1 ;
229 4 return $self->saveErrorString(0, "unexpected end of file", STATUS_ERROR);
230 }
231 }
232  
233 1184 $status = *$self->{Uncomp}->sync($temp_buf) ;
234  
235 1184 ▶ if ($status == STATUS_OK)
Branch: 1 branch
BranchTrueFalseTotal
if ($status == 0) 4 1180 1184
236 {
237 4 *$self->{Pending} .= $temp_buf ;
238 4 return 1 ;
239 }
240  
241 1180 ▶ last unless $status == STATUS_ERROR ;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == -1 0 1180 1180
242 }
243  
244 0 return 0;
245 }
246  
247 #sub performScan
248 #{
249 # my $self = shift ;
250 #
251 # my $status ;
252 # my $end_offset = 0;
253 #
254 # $status = $self->scan()
255 # #or return $self->saveErrorString(undef, "Error Scanning: $$error_ref", $self->errorNo) ;
256 # or return $self->saveErrorString(G_ERR, "Error Scanning: $status")
257 #
258 # $status = $self->zap($end_offset)
259 # or return $self->saveErrorString(G_ERR, "Error Zapping: $status");
260 # #or return $self->saveErrorString(undef, "Error Zapping: $$error_ref", $self->errorNo) ;
261 #
262 # #(*$obj->{Deflate}, $status) = $inf->createDeflate();
263 #
264 ## *$obj->{Header} = *$inf->{Info}{Header};
265 ## *$obj->{UnCompSize_32bit} =
266 ## *$obj->{BytesWritten} = *$inf->{UnCompSize_32bit} ;
267 ## *$obj->{CompSize_32bit} = *$inf->{CompSize_32bit} ;
268 #
269 #
270 ## if ( $outType eq 'buffer')
271 ## { substr( ${ *$self->{Buffer} }, $end_offset) = '' }
272 ## elsif ($outType eq 'handle' || $outType eq 'filename') {
273 ## *$self->{FH} = *$inf->{FH} ;
274 ## delete *$inf->{FH};
275 ## *$obj->{FH}->flush() ;
276 ## *$obj->{Handle} = 1 if $outType eq 'handle';
277 ##
278 ## #seek(*$obj->{FH}, $end_offset, SEEK_SET)
279 ## *$obj->{FH}->seek($end_offset, SEEK_SET)
280 ## or return $obj->saveErrorString(undef, $!, $!) ;
281 ## }
282 #
283 #}
284  
285 sub scan
286 61 ▶{
Subroutine scan: called CC=7 SCAR=19.9
Pod undocumented
287 61 my $self = shift ;
288  
289 61 ▶ return 1 if *$self->{Closed} ;
Branch: 1 branch
BranchTrueFalseTotal
if *$self->{"Closed"} 0 61 61
290 61 ▶ return 1 if !length *$self->{Pending} && *$self->{EndStream} ;
Branch: 1 branch
BranchTrueFalseTotal
if not length *$self->{"Pending"} and *$self->{"EndStream"} 60 1 61
Condition66%2/3
not length *$self->{"Pending"} and *$self->{"EndStream"}
!ll&&!rl&&r
0160
MC/DC50%1/2
not length *$self->{"Pending"} and *$self->{"EndStream"}
not length *$self->{"Pending"} *$self->{"EndStream"}
Truth table66%2/3
not(A) and B
A= not length *$self->{"Pending"}B= *$self->{"EndStream"}
ABresult
0X0
100
111
291  
292 1 my $buffer = '' ;
293 1 my $len = 0;
294  
295 $len = $self->_raw_read(\$buffer, 1)
296 1 ▶ while ! *$self->{EndStream} && $len >= 0 ;
Branch: 1 branch
BranchTrueFalseTotal
not *$self->{"EndStream"} and $len >= 0 and do { $len = $self->_raw_read(\$buffer, 1) } 1 1 2
Condition66%2/3
not *$self->{"EndStream"} and $len >= 0
!ll&&!rl&&r
011
MC/DC50%1/2
not *$self->{"EndStream"} and $len >= 0
not *$self->{"EndStream"} $len >= 0
Truth table66%2/3
not(A) and B
A= not *$self->{"EndStream"}B= $len >= 0
ABresult
0X0
100
111
297  
298 #return $len if $len < 0 ? $len : 0 ;
299 1 ▶ return $len < 0 ? 0 : 1 ;
Branch: 1 branch
BranchTrueFalseTotal
$len < 0 ? : 1 0 1
300 }
301  
302 sub zap
303 60 ▶{
Subroutine zap: called CC=5 SCAR=17.6
Pod undocumented
304 60 my $self = shift ;
305  
306 60 my $headerLength = *$self->{Info}{HeaderLength};
307 60 my $block_offset = $headerLength + *$self->{Uncomp}->getLastBlockOffset();
308 60 $_[0] = $headerLength + *$self->{Uncomp}->getEndOffset();
309 #printf "# End $_[0], headerlen $headerLength \n";
310 #printf "# block_offset $block_offset %x\n", $block_offset;
311 60 my $byte ;
312 60 ▶ ( $self->smartSeek($block_offset) &&
Branch: 1 branch
BranchTrueFalseTotal
$self->smartSeek($block_offset) and $self->smartRead(\$byte, 1) or return $self->saveErrorString(0, $!, $!) 60 0 60
Condition33%1/3
$self->smartSeek($block_offset) and $self->smartRead(\$byte, 1)
!ll&&!rl&&r
0060
MC/DC0%0/2
$self->smartSeek($block_offset) and $self->smartRead(\$byte, 1)
$self->smartSeek($block_offset) $self->smartRead(\$byte, 1)
Truth table33%1/3
A and B
A= $self->smartSeek($block_offset)B= $self->smartRead(\$byte, 1)
ABresult
0X0
100
111
313 $self->smartRead(\$byte, 1) )
314 or return $self->saveErrorString(0, $!, $!);
315  
316 #printf "#byte is %x\n", unpack('C*',$byte);
317 60 *$self->{Uncomp}->resetLastBlockByte($byte);
318 #printf "#to byte is %x\n", unpack('C*',$byte);
319  
320 60 ▶ ( $self->smartSeek($block_offset) &&
Branch: 1 branch
BranchTrueFalseTotal
$self->smartSeek($block_offset) and $self->smartWrite($byte) or return $self->saveErrorString(0, $!, $!) 60 0 60
Condition33%1/3
$self->smartSeek($block_offset) and $self->smartWrite($byte)
!ll&&!rl&&r
0060
MC/DC0%0/2
$self->smartSeek($block_offset) and $self->smartWrite($byte)
$self->smartSeek($block_offset) $self->smartWrite($byte)
Truth table33%1/3
A and B
A= $self->smartSeek($block_offset)B= $self->smartWrite($byte)
ABresult
0X0
100
111
321 $self->smartWrite($byte) )
322 or return $self->saveErrorString(0, $!, $!);
323  
324 #$self->smartSeek($end_offset, 1);
325  
326 60 return 1 ;
327 }
328  
329 sub createDeflate
330 60 ▶{
Subroutine createDeflate: called CC=2 SCAR=7.1
Pod undocumented
331 60 my $self = shift ;
332 my ($def, $status) = *$self->{Uncomp}->createDeflateStream(
333 -AppendOutput => 1,
334 -WindowBits => - MAX_WBITS,
335 -CRC32 => *$self->{Params}->getValue('crc32'),
336 60 -ADLER32 => *$self->{Params}->getValue('adler32'),
337 );
338  
339 60 ▶ return wantarray ? ($status, $def) : $def ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 60 60
340 }
341  
342  
343 96 1;
344  
345 __END__
« blib/lib/Compress/Zlib.pm ↑ Summary blib/lib/IO/Compress/Adapter/Bzip2.pm »