blib/lib/IO/Compress/Gzip.pm

filter: Statementstmt 99.1% 117 / 118 Branchbran 93.7% 60 / 64 Conditioncond 88.8% 24 / 27 MC/DCmcdc 72.2% 13 / 18 Subroutinesub 95.0% 19 / 20 Podpod 22.2% 2 / 9 totaltotal 91.8% 235 / 256 CC 41 SCAR 25.8
CC
41
Cov
96%
ckParams
23.0
mkHeader
15.1
getFileInfo
4.0
CRAP 13.2
« blib/lib/IO/Uncompress/Base.pm ↑ Summary blib/lib/IO/Compress/Zlib/Extra.pm »
1 package IO::Compress::Gzip ;
2  
3 33 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 33 require Exporter ;
8  
9 33 ▶use IO::Compress::RawDeflate 2.225 () ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 33 ▶use IO::Compress::Adapter::Deflate 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 33 ▶use IO::Compress::Base::Common 2.225 qw(:Status );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 33 ▶use IO::Compress::Gzip::Constants 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 33 ▶use IO::Compress::Zlib::Extra 2.225 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 BEGIN
17 33 ▶{
Subroutine BEGIN: called CC=2 SCAR=8.1
18 33 ▶ if (defined &utf8::downgrade )
Branch: 1 branch
BranchTrueFalseTotal
if (defined &utf8::downgrade) { } 33 0 33
19 33 { *noUTF8 = \&utf8::downgrade }
20 else
21 0 ▶ { *noUTF8 = sub {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 }
23  
24 33 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $GzipError);
25  
26 33 $VERSION = '2.225';
27 33 $GzipError = '' ;
28  
29 33 @ISA = qw(IO::Compress::RawDeflate Exporter);
30 33 @EXPORT_OK = qw( $GzipError gzip ) ;
31 33 %EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ;
32  
33 33 ▶$EXPORT_TAGS{all} = [ defined $EXPORT_TAGS{all} ? @{ $EXPORT_TAGS{all} } : (), @EXPORT_OK ] ;
Branch: 1 branch
BranchTrueFalseTotal
defined $IO::Compress::Gzip::EXPORT_TAGS{'all'} ? : 33 0 33
34 33 Exporter::export_ok_tags('all');
35  
36 sub new
37 322 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod documented
38 322 my $class = shift ;
39  
40 322 my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$GzipError);
41  
42 322 $obj->_create(undef, @_);
43 }
44  
45  
46 sub gzip
47 162 ▶{
Subroutine gzip: called CC=1 SCAR=0.0
Pod documented
48 162 my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$GzipError);
49 162 return $obj->_def(@_);
50 }
51  
52 #sub newHeader
53 #{
54 # my $self = shift ;
55 # #return GZIP_MINIMUM_HEADER ;
56 # return $self->mkHeader(*$self->{Got});
57 #}
58  
59 sub getExtraParams
60 487 ▶{
Subroutine getExtraParams: called CC=1 SCAR=0.0
Pod undocumented
61 487 my $self = shift ;
62  
63 return (
64 # zlib behaviour
65 487 $self->getZlibParams(),
66  
67 # Gzip header fields
68 'minimal' => [IO::Compress::Base::Common::Parse_boolean, 0],
69 'comment' => [IO::Compress::Base::Common::Parse_any, undef],
70 'name' => [IO::Compress::Base::Common::Parse_any, undef],
71 'time' => [IO::Compress::Base::Common::Parse_any, undef],
72 'textflag' => [IO::Compress::Base::Common::Parse_boolean, 0],
73 'headercrc' => [IO::Compress::Base::Common::Parse_boolean, 0],
74 'os_code' => [IO::Compress::Base::Common::Parse_unsigned, $Compress::Raw::Zlib::gzip_os_code],
75 'extrafield'=> [IO::Compress::Base::Common::Parse_any, undef],
76 'extraflags'=> [IO::Compress::Base::Common::Parse_any, undef],
77  
78 );
79 }
80  
81  
82 sub ckParams
83 483 ▶{
Subroutine ckParams: called CC=23 SCAR=31.4
Pod undocumented
84 483 my $self = shift ;
85 483 my $got = shift ;
86  
87 # gzip always needs crc32
88 483 $got->setValue('crc32' => 1);
89  
90 483 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $got->getValue("merge") 29 454 483
91 if $got->getValue('merge') ;
92  
93 454 my $strict = $got->getValue('strict') ;
94  
95  
96 {
97 454 ▶ if (! $got->parsed('time') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got->parsed("time")) 388 66 454
98 # Modification time defaults to now.
99 388 $got->setValue(time => time) ;
100 }
101  
102 # Check that the Name & Comment don't have embedded NULLs
103 # Also check that they only contain ISO 8859-1 chars.
104 454 ▶ if ($got->parsed('name') && defined $got->getValue('name')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("name") and defined $got->getValue("name")) 89 365 454
Condition100%3/3
$got->parsed("name") and defined $got->getValue("name")
!ll&&!rl&&r
364189
MC/DC100%2/2
$got->parsed("name") and defined $got->getValue("name")
$got->parsed("name") defined $got->getValue("name")
Truth table100%3/3
A and B
A= $got->parsed("name")B= defined $got->getValue("name")
ABresult
0X0
100
111
105 89 my $name = $got->getValue('name');
106  
107 89 ▶ return $self->saveErrorString(undef, "Null Character found in Name",
Branch: 1 branch
BranchTrueFalseTotal
if $strict and $name =~ /\x00/ 2 87 89
Condition100%3/3
$strict and $name =~ /\x00/
!ll&&!rl&&r
5822
MC/DC100%2/2
$strict and $name =~ /\x00/
$strict $name =~ /\x00/
Truth table100%3/3
A and B
A= $strictB= $name =~ /\x00/
ABresult
0X0
100
111
108 Z_DATA_ERROR)
109 if $strict && $name =~ /\x00/ ;
110  
111 87 ▶ return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Name",
Branch: 1 branch
BranchTrueFalseTotal
if $strict and $name =~ /$IO::Compress::Gzip::GZIP_FNAME_INVALID_CHAR_RE/o 1 86 87
Condition100%3/3
$strict and $name =~ /$IO::Compress::Gzip::GZIP_FNAME_INVALID_CHAR_RE/o
!ll&&!rl&&r
5811
MC/DC100%2/2
$strict and $name =~ /$IO::Compress::Gzip::GZIP_FNAME_INVALID_CHAR_RE/o
$strict $name =~ /$IO::Compress::Gzip::GZIP_FNAME_INVALID_CHAR_RE/o
Truth table100%3/3
A and B
A= $strictB= $name =~ /$IO::Compress::Gzip::GZIP_FNAME_INVALID_CHAR_RE/o
ABresult
0X0
100
111
112 Z_DATA_ERROR)
113 if $strict && $name =~ /$GZIP_FNAME_INVALID_CHAR_RE/o ;
114 }
115  
116 451 ▶ if ($got->parsed('comment') && defined $got->getValue('comment')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("comment") and defined $got->getValue("comment")) 39 412 451
Condition100%3/3
$got->parsed("comment") and defined $got->getValue("comment")
!ll&&!rl&&r
411139
MC/DC100%2/2
$got->parsed("comment") and defined $got->getValue("comment")
$got->parsed("comment") defined $got->getValue("comment")
Truth table100%3/3
A and B
A= $got->parsed("comment")B= defined $got->getValue("comment")
ABresult
0X0
100
111
117 39 my $comment = $got->getValue('comment');
118  
119 39 ▶ return $self->saveErrorString(undef, "Null Character found in Comment",
Branch: 1 branch
BranchTrueFalseTotal
if $strict and $comment =~ /\x00/ 2 37 39
Condition100%3/3
$strict and $comment =~ /\x00/
!ll&&!rl&&r
5322
MC/DC100%2/2
$strict and $comment =~ /\x00/
$strict $comment =~ /\x00/
Truth table100%3/3
A and B
A= $strictB= $comment =~ /\x00/
ABresult
0X0
100
111
120 Z_DATA_ERROR)
121 if $strict && $comment =~ /\x00/ ;
122  
123 37 ▶ return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Comment",
Branch: 1 branch
BranchTrueFalseTotal
if $strict and $comment =~ /$IO::Compress::Gzip::GZIP_FCOMMENT_INVALID_CHAR_RE/o 1 36 37
Condition100%3/3
$strict and $comment =~ /$IO::Compress::Gzip::GZIP_FCOMMENT_INVALID_CHAR_RE/o
!ll&&!rl&&r
5311
MC/DC100%2/2
$strict and $comment =~ /$IO::Compress::Gzip::GZIP_FCOMMENT_INVALID_CHAR_RE/o
$strict $comment =~ /$IO::Compress::Gzip::GZIP_FCOMMENT_INVALID_CHAR_RE/o
Truth table100%3/3
A and B
A= $strictB= $comment =~ /$IO::Compress::Gzip::GZIP_FCOMMENT_INVALID_CHAR_RE/o
ABresult
0X0
100
111
124 Z_DATA_ERROR)
125 if $strict && $comment =~ /$GZIP_FCOMMENT_INVALID_CHAR_RE/o;
126 }
127  
128 448 ▶ if ($got->parsed('os_code') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($got->parsed("os_code")) 6 442 448
129 6 my $value = $got->getValue('os_code');
130  
131 6 ▶ return $self->saveErrorString(undef, "OS_Code must be between 0 and 255, got '$value'")
Branch: 1 branch
BranchTrueFalseTotal
if $value < 0 or $value > 255 1 5 6
Condition66%2/3
$value < 0 or $value > 255
l!l&&r!l&&!r
015
MC/DC50%1/2
$value < 0 or $value > 255
$value < 0 $value > 255
Truth table66%2/3
A or B
A= $value < 0B= $value > 255
ABresult
1X1
011
000
132 if $value < 0 || $value > 255 ;
133  
134 }
135  
136 # gzip only supports Deflate at present
137 447 $got->setValue('method' => Z_DEFLATED) ;
138  
139 447 ▶ if ( ! $got->parsed('extraflags')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($got->parsed("extraflags")) 446 1 447
140 446 ▶ $got->setValue('extraflags' => 2)
Branch: 1 branch
BranchTrueFalseTotal
if $got->getValue("level") == Z_BEST_COMPRESSION() 1 445 446
141 if $got->getValue('level') == Z_BEST_COMPRESSION ;
142 446 ▶ $got->setValue('extraflags' => 4)
Branch: 1 branch
BranchTrueFalseTotal
if $got->getValue("level") == Z_BEST_SPEED() 1 445 446
143 if $got->getValue('level') == Z_BEST_SPEED ;
144 }
145  
146 447 my $data = $got->getValue('extrafield') ;
147 447 ▶ if (defined $data) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data) 82 365 447
148 82 my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, $strict, 1) ;
149 82 ▶ return $self->saveErrorString(undef, "Error with ExtraField Parameter: $bad", Z_DATA_ERROR)
Branch: 1 branch
BranchTrueFalseTotal
if $bad 20 62 82
150 if $bad ;
151  
152 62 $got->setValue('extrafield' => $data) ;
153 }
154 }
155  
156 427 return 1;
157 }
158  
159 sub mkTrailer
160 449 ▶{
Subroutine mkTrailer: called CC=1 SCAR=0.0
Pod undocumented
161 449 my $self = shift ;
162 return pack("V V", *$self->{Compress}->crc32(),
163 449 *$self->{UnCompSize}->get32bit());
164 }
165  
166 sub getInverseClass
167 25 ▶{
Subroutine getInverseClass: called CC=1 SCAR=0.0
Pod undocumented
168 33 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
169 25 return ('IO::Uncompress::Gunzip',
170 \$IO::Uncompress::Gunzip::GunzipError);
171 }
172  
173 sub getFileInfo
174 110 ▶{
Subroutine getFileInfo: called CC=4 SCAR=13.9
Pod undocumented
175 110 my $self = shift ;
176 110 my $params = shift;
177 110 my $filename = shift ;
178  
179 110 ▶ return if IO::Compress::Base::Common::isaScalar($filename);
Branch: 1 branch
BranchTrueFalseTotal
if IO::Compress::Base::Common::isaScalar($filename) 44 66 110
180  
181 66 my $defaultTime = (stat($filename))[9] ;
182  
183 66 ▶ $params->setValue('name' => $filename)
Branch: 1 branch
BranchTrueFalseTotal
unless $params->parsed("name") 59 7 66
184 if ! $params->parsed('name') ;
185  
186 66 ▶ $params->setValue('time' => $defaultTime)
Branch: 1 branch
BranchTrueFalseTotal
if not $params->parsed("time") 59 7 66
187 if ! $params->parsed('time') ;
188 }
189  
190  
191 sub mkHeader
192 429 ▶{
Subroutine mkHeader: called CC=15 SCAR=27.1
Pod undocumented
193 429 my $self = shift ;
194 429 my $param = shift ;
195  
196 # short-circuit if a minimal header is requested.
197 429 ▶ return GZIP_MINIMUM_HEADER if $param->getValue('minimal') ;
Branch: 1 branch
BranchTrueFalseTotal
if $param->getValue("minimal") 37 392 429
198  
199 # METHOD
200 392 my $method = $param->valueOrDefault('method', GZIP_CM_DEFLATED) ;
201  
202 # FLAGS
203 392 my $flags = GZIP_FLG_DEFAULT ;
204 392 ▶ $flags |= GZIP_FLG_FTEXT if $param->getValue('textflag') ;
Branch: 1 branch
BranchTrueFalseTotal
if $param->getValue("textflag") 7 385 392
205 392 ▶ $flags |= GZIP_FLG_FHCRC if $param->getValue('headercrc') ;
Branch: 1 branch
BranchTrueFalseTotal
if $param->getValue("headercrc") 51 341 392
206 392 ▶ $flags |= GZIP_FLG_FEXTRA if $param->wantValue('extrafield') ;
Branch: 1 branch
BranchTrueFalseTotal
if $param->wantValue("extrafield") 62 330 392
207 392 ▶ $flags |= GZIP_FLG_FNAME if $param->wantValue('name') ;
Branch: 1 branch
BranchTrueFalseTotal
if $param->wantValue("name") 95 297 392
208 392 ▶ $flags |= GZIP_FLG_FCOMMENT if $param->wantValue('comment') ;
Branch: 1 branch
BranchTrueFalseTotal
if $param->wantValue("comment") 55 337 392
209  
210 # MTIME
211 392 my $time = $param->valueOrDefault('time', GZIP_MTIME_DEFAULT) ;
212  
213 # EXTRA FLAGS
214 392 my $extra_flags = $param->valueOrDefault('extraflags', GZIP_XFL_DEFAULT);
215  
216 # OS CODE
217 392 my $os_code = $param->valueOrDefault('os_code', GZIP_OS_DEFAULT) ;
218  
219  
220 392 my $out = pack("C4 V C C",
221 GZIP_ID1, # ID1
222 GZIP_ID2, # ID2
223 $method, # Compression Method
224 $flags, # Flags
225 $time, # Modification Time
226 $extra_flags, # Extra Flags
227 $os_code, # Operating System Code
228 ) ;
229  
230 # EXTRA
231 392 ▶ if ($flags & GZIP_FLG_FEXTRA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 4) 62 330 392
232 62 my $extra = $param->getValue('extrafield') ;
233 62 $out .= pack("v", length $extra) . $extra ;
234 }
235  
236 # NAME
237 392 ▶ if ($flags & GZIP_FLG_FNAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 8) 95 297 392
238 95 my $name .= $param->getValue('name') ;
239 95 $name =~ s/\x00.*$//;
240 95 $out .= $name ;
241 # Terminate the filename with NULL unless it already is
242 95 ▶ $out .= GZIP_NULL_BYTE
Branch: 1 branch
BranchTrueFalseTotal
if not length $name or substr($name, 1, -1) ne "\0" 95 0 95
Condition66%2/3
not length $name or substr($name, 1, -1) ne "\0"
l!l&&r!l&&!r
7880
MC/DC0%0/2
not length $name or substr($name, 1, -1) ne "\0"
not length $name substr($name, 1, -1) ne "\0"
Truth table66%2/3
not(A) or B
A= not length $nameB= substr($name, 1, -1) ne "\0"
ABresult
1X1
011
000
243 if !length $name or
244 substr($name, 1, -1) ne GZIP_NULL_BYTE ;
245 }
246  
247 # COMMENT
248 392 ▶ if ($flags & GZIP_FLG_FCOMMENT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 16) 55 337 392
249 55 my $comment .= $param->getValue('comment') ;
250 55 $comment =~ s/\x00.*$//;
251 55 $out .= $comment ;
252 # Terminate the comment with NULL unless it already is
253 55 ▶ $out .= GZIP_NULL_BYTE
Branch: 1 branch
BranchTrueFalseTotal
if not length $comment or substr($comment, 1, -1) ne "\0" 55 0 55
Condition66%2/3
not length $comment or substr($comment, 1, -1) ne "\0"
l!l&&r!l&&!r
1540
MC/DC0%0/2
not length $comment or substr($comment, 1, -1) ne "\0"
not length $comment substr($comment, 1, -1) ne "\0"
Truth table66%2/3
not(A) or B
A= not length $commentB= substr($comment, 1, -1) ne "\0"
ABresult
1X1
011
000
254 if ! length $comment or
255 substr($comment, 1, -1) ne GZIP_NULL_BYTE;
256 }
257  
258 # HEADER CRC
259 392 ▶ $out .= pack("v", Compress::Raw::Zlib::crc32($out) & 0x00FF )
Branch: 1 branch
BranchTrueFalseTotal
if $param->getValue("headercrc") 51 341 392
260 if $param->getValue('headercrc') ;
261  
262 392 noUTF8($out);
263  
264 392 return $out ;
265 }
266  
267 sub mkFinalTrailer
268 418 ▶{
Subroutine mkFinalTrailer: called CC=1 SCAR=0.0
Pod undocumented
269 418 return '';
270 }
271  
272 33 1;
273  
274 __END__
« blib/lib/IO/Uncompress/Base.pm ↑ Summary blib/lib/IO/Compress/Zlib/Extra.pm »