Filename | /usr/lib/perl/5.10/IO/Compress/Gzip.pm |
Statements | Executed 36 statements in 2.01ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.47ms | 9.27ms | BEGIN@11 | IO::Compress::Gzip::
1 | 1 | 1 | 1.41ms | 3.18ms | BEGIN@15 | IO::Compress::Gzip::
1 | 1 | 1 | 1.03ms | 1.47ms | BEGIN@16 | IO::Compress::Gzip::
1 | 1 | 1 | 23µs | 29µs | BEGIN@6 | IO::Compress::Gzip::
1 | 1 | 1 | 19µs | 291µs | BEGIN@13 | IO::Compress::Gzip::
1 | 1 | 1 | 15µs | 235µs | BEGIN@14 | IO::Compress::Gzip::
1 | 1 | 1 | 13µs | 32µs | BEGIN@7 | IO::Compress::Gzip::
1 | 1 | 1 | 10µs | 13µs | BEGIN@8 | IO::Compress::Gzip::
1 | 1 | 1 | 8µs | 8µs | BEGIN@19 | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | __ANON__[:23] | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | ckParams | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | getExtraParams | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | getFileInfo | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | getInverseClass | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | gzip | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | mkFinalTrailer | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | mkHeader | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | mkTrailer | IO::Compress::Gzip::
0 | 0 | 0 | 0s | 0s | new | IO::Compress::Gzip::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package IO::Compress::Gzip ; | ||||
3 | |||||
4 | 1 | 18µs | require 5.004 ; | ||
5 | |||||
6 | 3 | 31µs | 2 | 35µs | # spent 29µs (23+6) within IO::Compress::Gzip::BEGIN@6 which was called:
# once (23µs+6µs) by Compress::Zlib::BEGIN@13 at line 6 # spent 29µs making 1 call to IO::Compress::Gzip::BEGIN@6
# spent 6µs making 1 call to strict::import |
7 | 3 | 28µs | 2 | 51µs | # spent 32µs (13+19) within IO::Compress::Gzip::BEGIN@7 which was called:
# once (13µs+19µs) by Compress::Zlib::BEGIN@13 at line 7 # spent 32µs making 1 call to IO::Compress::Gzip::BEGIN@7
# spent 19µs making 1 call to warnings::import |
8 | 3 | 29µs | 2 | 16µs | # spent 13µs (10+3) within IO::Compress::Gzip::BEGIN@8 which was called:
# once (10µs+3µs) by Compress::Zlib::BEGIN@13 at line 8 # spent 13µs making 1 call to IO::Compress::Gzip::BEGIN@8
# spent 3µs making 1 call to bytes::import |
9 | |||||
10 | |||||
11 | 3 | 162µs | 3 | 9.32ms | # spent 9.27ms (1.47+7.80) within IO::Compress::Gzip::BEGIN@11 which was called:
# once (1.47ms+7.80ms) by Compress::Zlib::BEGIN@13 at line 11 # spent 9.27ms making 1 call to IO::Compress::Gzip::BEGIN@11
# spent 26µs making 1 call to Exporter::import
# spent 20µs making 1 call to UNIVERSAL::VERSION |
12 | |||||
13 | 3 | 62µs | 3 | 563µs | # spent 291µs (19+272) within IO::Compress::Gzip::BEGIN@13 which was called:
# once (19µs+272µs) by Compress::Zlib::BEGIN@13 at line 13 # spent 291µs making 1 call to IO::Compress::Gzip::BEGIN@13
# spent 258µs making 1 call to Exporter::import
# spent 14µs making 1 call to UNIVERSAL::VERSION |
14 | 3 | 75µs | 3 | 455µs | # spent 235µs (15+220) within IO::Compress::Gzip::BEGIN@14 which was called:
# once (15µs+220µs) by Compress::Zlib::BEGIN@13 at line 14 # spent 235µs making 1 call to IO::Compress::Gzip::BEGIN@14
# spent 206µs making 1 call to Exporter::import
# spent 14µs making 1 call to UNIVERSAL::VERSION |
15 | 3 | 188µs | 3 | 3.52ms | # spent 3.18ms (1.41+1.77) within IO::Compress::Gzip::BEGIN@15 which was called:
# once (1.41ms+1.77ms) by Compress::Zlib::BEGIN@13 at line 15 # spent 3.18ms making 1 call to IO::Compress::Gzip::BEGIN@15
# spent 330µs making 1 call to Exporter::import
# spent 19µs making 1 call to UNIVERSAL::VERSION |
16 | 3 | 203µs | 2 | 1.48ms | # spent 1.47ms (1.03+436µs) within IO::Compress::Gzip::BEGIN@16 which was called:
# once (1.03ms+436µs) by Compress::Zlib::BEGIN@13 at line 16 # spent 1.47ms making 1 call to IO::Compress::Gzip::BEGIN@16
# spent 10µs making 1 call to UNIVERSAL::VERSION |
17 | |||||
18 | BEGIN | ||||
19 | # spent 8µs within IO::Compress::Gzip::BEGIN@19 which was called:
# once (8µs+0s) by Compress::Zlib::BEGIN@13 at line 24 | ||||
20 | 1 | 8µs | if (defined &utf8::downgrade ) | ||
21 | { *noUTF8 = \&utf8::downgrade } | ||||
22 | else | ||||
23 | { *noUTF8 = sub {} } | ||||
24 | 1 | 1.16ms | 1 | 8µs | } # spent 8µs making 1 call to IO::Compress::Gzip::BEGIN@19 |
25 | |||||
26 | 1 | 600ns | require Exporter ; | ||
27 | |||||
28 | 1 | 1µs | our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $GzipError); | ||
29 | |||||
30 | 1 | 500ns | $VERSION = '2.020'; | ||
31 | 1 | 300ns | $GzipError = '' ; | ||
32 | |||||
33 | 1 | 20µs | @ISA = qw(Exporter IO::Compress::RawDeflate); | ||
34 | 1 | 1µs | @EXPORT_OK = qw( $GzipError gzip ) ; | ||
35 | 1 | 5µs | %EXPORT_TAGS = %IO::Compress::RawDeflate::DEFLATE_CONSTANTS ; | ||
36 | 1 | 2µs | push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; | ||
37 | 1 | 4µs | 1 | 30µs | Exporter::export_ok_tags('all'); # spent 30µs making 1 call to Exporter::export_ok_tags |
38 | |||||
39 | sub new | ||||
40 | { | ||||
41 | my $class = shift ; | ||||
42 | |||||
43 | my $obj = createSelfTiedObject($class, \$GzipError); | ||||
44 | |||||
45 | $obj->_create(undef, @_); | ||||
46 | } | ||||
47 | |||||
48 | |||||
49 | sub gzip | ||||
50 | { | ||||
51 | my $obj = createSelfTiedObject(undef, \$GzipError); | ||||
52 | return $obj->_def(@_); | ||||
53 | } | ||||
54 | |||||
55 | #sub newHeader | ||||
56 | #{ | ||||
57 | # my $self = shift ; | ||||
58 | # #return GZIP_MINIMUM_HEADER ; | ||||
59 | # return $self->mkHeader(*$self->{Got}); | ||||
60 | #} | ||||
61 | |||||
62 | sub getExtraParams | ||||
63 | { | ||||
64 | my $self = shift ; | ||||
65 | |||||
66 | return ( | ||||
67 | # zlib behaviour | ||||
68 | $self->getZlibParams(), | ||||
69 | |||||
70 | # Gzip header fields | ||||
71 | 'Minimal' => [0, 1, Parse_boolean, 0], | ||||
72 | 'Comment' => [0, 1, Parse_any, undef], | ||||
73 | 'Name' => [0, 1, Parse_any, undef], | ||||
74 | 'Time' => [0, 1, Parse_any, undef], | ||||
75 | 'TextFlag' => [0, 1, Parse_boolean, 0], | ||||
76 | 'HeaderCRC' => [0, 1, Parse_boolean, 0], | ||||
77 | 'OS_Code' => [0, 1, Parse_unsigned, $Compress::Raw::Zlib::gzip_os_code], | ||||
78 | 'ExtraField'=> [0, 1, Parse_any, undef], | ||||
79 | 'ExtraFlags'=> [0, 1, Parse_any, undef], | ||||
80 | |||||
81 | ); | ||||
82 | } | ||||
83 | |||||
84 | |||||
85 | sub ckParams | ||||
86 | { | ||||
87 | my $self = shift ; | ||||
88 | my $got = shift ; | ||||
89 | |||||
90 | # gzip always needs crc32 | ||||
91 | $got->value('CRC32' => 1); | ||||
92 | |||||
93 | return 1 | ||||
94 | if $got->value('Merge') ; | ||||
95 | |||||
96 | my $strict = $got->value('Strict') ; | ||||
97 | |||||
98 | |||||
99 | { | ||||
100 | if (! $got->parsed('Time') ) { | ||||
101 | # Modification time defaults to now. | ||||
102 | $got->value('Time' => time) ; | ||||
103 | } | ||||
104 | |||||
105 | # Check that the Name & Comment don't have embedded NULLs | ||||
106 | # Also check that they only contain ISO 8859-1 chars. | ||||
107 | if ($got->parsed('Name') && defined $got->value('Name')) { | ||||
108 | my $name = $got->value('Name'); | ||||
109 | |||||
110 | return $self->saveErrorString(undef, "Null Character found in Name", | ||||
111 | Z_DATA_ERROR) | ||||
112 | if $strict && $name =~ /\x00/ ; | ||||
113 | |||||
114 | return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Name", | ||||
115 | Z_DATA_ERROR) | ||||
116 | if $strict && $name =~ /$GZIP_FNAME_INVALID_CHAR_RE/o ; | ||||
117 | } | ||||
118 | |||||
119 | if ($got->parsed('Comment') && defined $got->value('Comment')) { | ||||
120 | my $comment = $got->value('Comment'); | ||||
121 | |||||
122 | return $self->saveErrorString(undef, "Null Character found in Comment", | ||||
123 | Z_DATA_ERROR) | ||||
124 | if $strict && $comment =~ /\x00/ ; | ||||
125 | |||||
126 | return $self->saveErrorString(undef, "Non ISO 8859-1 Character found in Comment", | ||||
127 | Z_DATA_ERROR) | ||||
128 | if $strict && $comment =~ /$GZIP_FCOMMENT_INVALID_CHAR_RE/o; | ||||
129 | } | ||||
130 | |||||
131 | if ($got->parsed('OS_Code') ) { | ||||
132 | my $value = $got->value('OS_Code'); | ||||
133 | |||||
134 | return $self->saveErrorString(undef, "OS_Code must be between 0 and 255, got '$value'") | ||||
135 | if $value < 0 || $value > 255 ; | ||||
136 | |||||
137 | } | ||||
138 | |||||
139 | # gzip only supports Deflate at present | ||||
140 | $got->value('Method' => Z_DEFLATED) ; | ||||
141 | |||||
142 | if ( ! $got->parsed('ExtraFlags')) { | ||||
143 | $got->value('ExtraFlags' => 2) | ||||
144 | if $got->value('Level') == Z_BEST_SPEED ; | ||||
145 | $got->value('ExtraFlags' => 4) | ||||
146 | if $got->value('Level') == Z_BEST_COMPRESSION ; | ||||
147 | } | ||||
148 | |||||
149 | my $data = $got->value('ExtraField') ; | ||||
150 | if (defined $data) { | ||||
151 | my $bad = IO::Compress::Zlib::Extra::parseExtraField($data, $strict, 1) ; | ||||
152 | return $self->saveErrorString(undef, "Error with ExtraField Parameter: $bad", Z_DATA_ERROR) | ||||
153 | if $bad ; | ||||
154 | |||||
155 | $got->value('ExtraField', $data) ; | ||||
156 | } | ||||
157 | } | ||||
158 | |||||
159 | return 1; | ||||
160 | } | ||||
161 | |||||
162 | sub mkTrailer | ||||
163 | { | ||||
164 | my $self = shift ; | ||||
165 | return pack("V V", *$self->{Compress}->crc32(), | ||||
166 | *$self->{UnCompSize}->get32bit()); | ||||
167 | } | ||||
168 | |||||
169 | sub getInverseClass | ||||
170 | { | ||||
171 | return ('IO::Uncompress::Gunzip', | ||||
172 | \$IO::Uncompress::Gunzip::GunzipError); | ||||
173 | } | ||||
174 | |||||
175 | sub getFileInfo | ||||
176 | { | ||||
177 | my $self = shift ; | ||||
178 | my $params = shift; | ||||
179 | my $filename = shift ; | ||||
180 | |||||
181 | my $defaultTime = (stat($filename))[9] ; | ||||
182 | |||||
183 | $params->value('Name' => $filename) | ||||
184 | if ! $params->parsed('Name') ; | ||||
185 | |||||
186 | $params->value('Time' => $defaultTime) | ||||
187 | if ! $params->parsed('Time') ; | ||||
188 | } | ||||
189 | |||||
190 | |||||
191 | sub mkHeader | ||||
192 | { | ||||
193 | my $self = shift ; | ||||
194 | my $param = shift ; | ||||
195 | |||||
196 | # stort-circuit if a minimal header is requested. | ||||
197 | return GZIP_MINIMUM_HEADER if $param->value('Minimal') ; | ||||
198 | |||||
199 | # METHOD | ||||
200 | my $method = $param->valueOrDefault('Method', GZIP_CM_DEFLATED) ; | ||||
201 | |||||
202 | # FLAGS | ||||
203 | my $flags = GZIP_FLG_DEFAULT ; | ||||
204 | $flags |= GZIP_FLG_FTEXT if $param->value('TextFlag') ; | ||||
205 | $flags |= GZIP_FLG_FHCRC if $param->value('HeaderCRC') ; | ||||
206 | $flags |= GZIP_FLG_FEXTRA if $param->wantValue('ExtraField') ; | ||||
207 | $flags |= GZIP_FLG_FNAME if $param->wantValue('Name') ; | ||||
208 | $flags |= GZIP_FLG_FCOMMENT if $param->wantValue('Comment') ; | ||||
209 | |||||
210 | # MTIME | ||||
211 | my $time = $param->valueOrDefault('Time', GZIP_MTIME_DEFAULT) ; | ||||
212 | |||||
213 | # EXTRA FLAGS | ||||
214 | my $extra_flags = $param->valueOrDefault('ExtraFlags', GZIP_XFL_DEFAULT); | ||||
215 | |||||
216 | # OS CODE | ||||
217 | my $os_code = $param->valueOrDefault('OS_Code', GZIP_OS_DEFAULT) ; | ||||
218 | |||||
219 | |||||
220 | 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 | if ($flags & GZIP_FLG_FEXTRA) { | ||||
232 | my $extra = $param->value('ExtraField') ; | ||||
233 | $out .= pack("v", length $extra) . $extra ; | ||||
234 | } | ||||
235 | |||||
236 | # NAME | ||||
237 | if ($flags & GZIP_FLG_FNAME) { | ||||
238 | my $name .= $param->value('Name') ; | ||||
239 | $name =~ s/\x00.*$//; | ||||
240 | $out .= $name ; | ||||
241 | # Terminate the filename with NULL unless it already is | ||||
242 | $out .= GZIP_NULL_BYTE | ||||
243 | if !length $name or | ||||
244 | substr($name, 1, -1) ne GZIP_NULL_BYTE ; | ||||
245 | } | ||||
246 | |||||
247 | # COMMENT | ||||
248 | if ($flags & GZIP_FLG_FCOMMENT) { | ||||
249 | my $comment .= $param->value('Comment') ; | ||||
250 | $comment =~ s/\x00.*$//; | ||||
251 | $out .= $comment ; | ||||
252 | # Terminate the comment with NULL unless it already is | ||||
253 | $out .= GZIP_NULL_BYTE | ||||
254 | if ! length $comment or | ||||
255 | substr($comment, 1, -1) ne GZIP_NULL_BYTE; | ||||
256 | } | ||||
257 | |||||
258 | # HEADER CRC | ||||
259 | $out .= pack("v", crc32($out) & 0x00FF ) if $param->value('HeaderCRC') ; | ||||
260 | |||||
261 | noUTF8($out); | ||||
262 | |||||
263 | return $out ; | ||||
264 | } | ||||
265 | |||||
266 | sub mkFinalTrailer | ||||
267 | { | ||||
268 | return ''; | ||||
269 | } | ||||
270 | |||||
271 | 1 | 12µs | 1; | ||
272 | |||||
273 | __END__ |