Skilletor/Gzip.pm

filter: Statementstmt 80.0% 36 / 45 Branchbran 37.5% 6 / 16 Conditioncond 25.0% 2 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 88.8% 8 / 9 Podpod 100% 2 / 2 totaltotal 63.5% 54 / 85 CC 12 SCAR 24.0
CC
12
Cov
64%
_run
17.7
inflate_sync
12.0
BEGIN
1.0
CRAP 11.0
« Skilletor/Lock.pm ↑ Summary Skilletor/Tar.pm »
1 package Skilletor::Gzip;
2 # ABSTRACT: gunzip and inflate as Node's zlib binding does them, with zlib's messages
3  
4 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 35 ▶use Compress::Raw::Zlib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use Skilletor::Error::Source;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 35 our $VERSION = '0.001';
12  
13 35 our @EXPORT_OK = qw( gunzip_sync inflate_sync );
14  
15 1 ▶sub _fail { Skilletor::Error::Source->throw( $_[0] ) }
Subroutine _fail: called CC=1 SCAR=0.0
16  
17 # One zlib stream over all of $input. $gunzip: after a member's end, a 0x00 byte ends the
18 # input (padding); any other byte starts the next member – as node_zlib.cc does.
19 14 ▶sub _run {
Subroutine _run: called CC=10 SCAR=28.7
20 14 my ( $input, $window_bits, $gunzip ) = @_;
21 14 my ( $z, $status ) = Compress::Raw::Zlib::Inflate->new(
22 -WindowBits => $window_bits,
23 -ConsumeInput => 1,
24 -LimitOutput => 0,
25 -Bufsize => 65536,
26 );
27 14 ▶ _fail( 'zlib: '.$status ) unless $z;
Branch: 1 branch
BranchTrueFalseTotal
unless $z 0 14 14
28 14 my $out = '';
29 14 my $in = $input;
30 14 while (1) {
31 14 my $chunk = '';
32 14 my $st = $z->inflate( $in, $chunk );
33 14 $out .= $chunk;
34 14 ▶ if ( $st == Compress::Raw::Zlib::Z_STREAM_END() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st == Compress::Raw::Zlib::Z_STREAM_END()) 13 1 14
35 13 ▶ last unless $gunzip && length $in;
Branch: 1 branch
BranchTrueFalseTotal
unless $gunzip and length $in 13 0 13
Condition33%1/3
$gunzip and length $in
!ll&&!rl&&r
0130
MC/DC0%0/2
$gunzip and length $in
$gunzip length $in
Truth table33%1/3
A and B
A= $gunzipB= length $in
ABresult
0X0
100
111
36 0 ▶ last if substr( $in, 0, 1 ) eq "\0";
Branch: 1 branch
BranchTrueFalseTotal
if substr($in, 0, 1) eq "\0" 0 0 0
37 0 $z->inflateReset;
38 0 next;
39 }
40 1 ▶ if ( $st == Compress::Raw::Zlib::Z_OK() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st == Compress::Raw::Zlib::Z_OK()) 0 1 1
41 0 ▶ next if length $in;
Branch: 1 branch
BranchTrueFalseTotal
if length $in 0 0 0
42 0 _fail('unexpected end of file');
43 }
44 1 ▶ if ( $st == Compress::Raw::Zlib::Z_BUF_ERROR() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($st == Compress::Raw::Zlib::Z_BUF_ERROR()) 0 1 1
45 0 _fail('unexpected end of file');
46 }
47 1 ▶ _fail( $z->msg // "$st" );
Condition50%1/2
$z->msg // "$st"
l!l
10
MC/DC0%0/1
$z->msg // "$st"
$z->msg
Truth table50%1/2
A
A= $z->msg
Aresult
11
00
48 }
49 13 return $out;
50 }
51  
52 14 ▶sub gunzip_sync {
Subroutine gunzip_sync: called CC=1 SCAR=0.0
Pod documented
53 14 my ( $bytes ) = @_;
54 14 return _run( $bytes, Compress::Raw::Zlib::WANT_GZIP(), 1 );
55 }
56  
57 # Content-Encoding: deflate – zlib-wrapped when the first byte says so, else raw (undici).
58 0 ▶sub inflate_sync {
Subroutine inflate_sync: not called CC=3 SCAR=24.8
Pod documented
59 0 my ( $bytes ) = @_;
60 0 ▶ my $zlib = length $bytes && ( ord( substr $bytes, 0, 1 ) & 0x0F ) == 0x08;
Condition0%0/3
length $bytes && (ord substr($bytes, 0, 1) & 15) == 8
!ll&&!rl&&r
000
MC/DC0%0/2
length $bytes && (ord substr($bytes, 0, 1) & 15) == 8
length $bytes (ord substr($bytes, 0, 1) & 15) == 8
Truth table0%0/3
A && B
A= length $bytesB= (ord substr($bytes, 0, 1) & 15) == 8
ABresult
0X0
100
111
61 0 ▶ return _run( $bytes, $zlib ? Compress::Raw::Zlib::MAX_WBITS() : -Compress::Raw::Zlib::MAX_WBITS(), 0 );
Branch: 1 branch
BranchTrueFalseTotal
$zlib ? : 0 0 0
62 }
63  
64 35 1;
65  
66 __END__
« Skilletor/Lock.pm ↑ Summary Skilletor/Tar.pm »