Filename | /usr/lib/perl/5.10/IO/Compress/Base.pm |
Statements | Executed 63 statements in 4.68ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 34µs | 94µs | BEGIN@17 | IO::Compress::Base::
1 | 1 | 1 | 26µs | 287µs | BEGIN@9 | IO::Compress::Base::
1 | 1 | 1 | 24µs | 220µs | BEGIN@11 | IO::Compress::Base::
1 | 1 | 1 | 22µs | 28µs | BEGIN@6 | IO::Compress::Base::
6 | 6 | 1 | 21µs | 21µs | _notAvailable | IO::Compress::Base::
1 | 1 | 1 | 16µs | 48µs | BEGIN@847 | IO::Compress::Base::
1 | 1 | 1 | 15µs | 37µs | BEGIN@7 | IO::Compress::Base::
1 | 1 | 1 | 15µs | 37µs | BEGIN@264 | IO::Compress::Base::
1 | 1 | 1 | 12µs | 68µs | BEGIN@16 | IO::Compress::Base::
1 | 1 | 1 | 11µs | 51µs | BEGIN@12 | IO::Compress::Base::
1 | 1 | 1 | 10µs | 12µs | BEGIN@18 | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | DESTROY | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | TIEHANDLE | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | UNTIE | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:916] | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | _create | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | _def | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | _singleTarget | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | _wr2 | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | _writeFinalTrailer | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | _writeTrailer | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | addInterStream | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | autoflush | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | binmode | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | checkParams | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | ckOutputParam | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | close | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | closeError | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | croakError | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | eof | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | error | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | errorNo | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | fileno | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | filterUncompressed | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | flush | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | getFileInfo | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | getOneShotParams | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | input_line_number | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | newStream | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | opened | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | output | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | |
0 | 0 | 0 | 0s | 0s | printf | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | reset | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | saveErrorString | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | saveStatus | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | seek | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | syswrite | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | tell | IO::Compress::Base::
0 | 0 | 0 | 0s | 0s | writeAt | IO::Compress::Base::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | |||||
2 | package IO::Compress::Base ; | ||||
3 | |||||
4 | 1 | 22µs | require 5.004 ; | ||
5 | |||||
6 | 3 | 54µs | 2 | 35µs | # spent 28µs (22+7) within IO::Compress::Base::BEGIN@6 which was called:
# once (22µs+7µs) by IO::Compress::RawDeflate::BEGIN@10 at line 6 # spent 28µs making 1 call to IO::Compress::Base::BEGIN@6
# spent 6µs making 1 call to strict::import |
7 | 3 | 38µs | 2 | 58µs | # spent 37µs (15+22) within IO::Compress::Base::BEGIN@7 which was called:
# once (15µs+22µs) by IO::Compress::RawDeflate::BEGIN@10 at line 7 # spent 37µs making 1 call to IO::Compress::Base::BEGIN@7
# spent 22µs making 1 call to warnings::import |
8 | |||||
9 | 3 | 76µs | 3 | 548µs | # spent 287µs (26+261) within IO::Compress::Base::BEGIN@9 which was called:
# once (26µs+261µs) by IO::Compress::RawDeflate::BEGIN@10 at line 9 # spent 287µs making 1 call to IO::Compress::Base::BEGIN@9
# spent 241µs making 1 call to Exporter::import
# spent 20µs making 1 call to UNIVERSAL::VERSION |
10 | |||||
11 | 3 | 44µs | 2 | 416µs | # spent 220µs (24+196) within IO::Compress::Base::BEGIN@11 which was called:
# once (24µs+196µs) by IO::Compress::RawDeflate::BEGIN@10 at line 11 # spent 220µs making 1 call to IO::Compress::Base::BEGIN@11
# spent 196µs making 1 call to Exporter::import |
12 | 3 | 31µs | 2 | 91µs | # spent 51µs (11+40) within IO::Compress::Base::BEGIN@12 which was called:
# once (11µs+40µs) by IO::Compress::RawDeflate::BEGIN@10 at line 12 # spent 51µs making 1 call to IO::Compress::Base::BEGIN@12
# spent 40µs making 1 call to Exporter::import |
13 | |||||
14 | #use File::Glob; | ||||
15 | #require Exporter ; | ||||
16 | 3 | 41µs | 2 | 125µs | # spent 68µs (12+56) within IO::Compress::Base::BEGIN@16 which was called:
# once (12µs+56µs) by IO::Compress::RawDeflate::BEGIN@10 at line 16 # spent 68µs making 1 call to IO::Compress::Base::BEGIN@16
# spent 56µs making 1 call to Exporter::import |
17 | 3 | 55µs | 2 | 154µs | # spent 94µs (34+60) within IO::Compress::Base::BEGIN@17 which was called:
# once (34µs+60µs) by IO::Compress::RawDeflate::BEGIN@10 at line 17 # spent 94µs making 1 call to IO::Compress::Base::BEGIN@17
# spent 60µs making 1 call to Exporter::import |
18 | 3 | 1.13ms | 2 | 15µs | # spent 12µs (10+3) within IO::Compress::Base::BEGIN@18 which was called:
# once (10µs+3µs) by IO::Compress::RawDeflate::BEGIN@10 at line 18 # spent 12µs making 1 call to IO::Compress::Base::BEGIN@18
# spent 3µs making 1 call to bytes::import |
19 | |||||
20 | 1 | 1µs | our (@ISA, $VERSION); | ||
21 | 1 | 18µs | @ISA = qw(Exporter IO::File); | ||
22 | |||||
23 | 1 | 500ns | $VERSION = '2.020'; | ||
24 | |||||
25 | #Can't locate object method "SWASHNEW" via package "utf8" (perhaps you forgot to load "utf8"?) at .../ext/Compress-Zlib/Gzip/blib/lib/Compress/Zlib/Common.pm line 16. | ||||
26 | |||||
27 | sub saveStatus | ||||
28 | { | ||||
29 | my $self = shift ; | ||||
30 | ${ *$self->{ErrorNo} } = shift() + 0 ; | ||||
31 | ${ *$self->{Error} } = '' ; | ||||
32 | |||||
33 | return ${ *$self->{ErrorNo} } ; | ||||
34 | } | ||||
35 | |||||
36 | |||||
37 | sub saveErrorString | ||||
38 | { | ||||
39 | my $self = shift ; | ||||
40 | my $retval = shift ; | ||||
41 | ${ *$self->{Error} } = shift ; | ||||
42 | ${ *$self->{ErrorNo} } = shift() + 0 if @_ ; | ||||
43 | |||||
44 | return $retval; | ||||
45 | } | ||||
46 | |||||
47 | sub croakError | ||||
48 | { | ||||
49 | my $self = shift ; | ||||
50 | $self->saveErrorString(0, $_[0]); | ||||
51 | croak $_[0]; | ||||
52 | } | ||||
53 | |||||
54 | sub closeError | ||||
55 | { | ||||
56 | my $self = shift ; | ||||
57 | my $retval = shift ; | ||||
58 | |||||
59 | my $errno = *$self->{ErrorNo}; | ||||
60 | my $error = ${ *$self->{Error} }; | ||||
61 | |||||
62 | $self->close(); | ||||
63 | |||||
64 | *$self->{ErrorNo} = $errno ; | ||||
65 | ${ *$self->{Error} } = $error ; | ||||
66 | |||||
67 | return $retval; | ||||
68 | } | ||||
69 | |||||
- - | |||||
72 | sub error | ||||
73 | { | ||||
74 | my $self = shift ; | ||||
75 | return ${ *$self->{Error} } ; | ||||
76 | } | ||||
77 | |||||
78 | sub errorNo | ||||
79 | { | ||||
80 | my $self = shift ; | ||||
81 | return ${ *$self->{ErrorNo} } ; | ||||
82 | } | ||||
83 | |||||
84 | |||||
85 | sub writeAt | ||||
86 | { | ||||
87 | my $self = shift ; | ||||
88 | my $offset = shift; | ||||
89 | my $data = shift; | ||||
90 | |||||
91 | if (defined *$self->{FH}) { | ||||
92 | my $here = tell(*$self->{FH}); | ||||
93 | return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) | ||||
94 | if $here < 0 ; | ||||
95 | seek(*$self->{FH}, $offset, SEEK_SET) | ||||
96 | or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ; | ||||
97 | defined *$self->{FH}->write($data, length $data) | ||||
98 | or return $self->saveErrorString(undef, $!, $!) ; | ||||
99 | seek(*$self->{FH}, $here, SEEK_SET) | ||||
100 | or return $self->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ; | ||||
101 | } | ||||
102 | else { | ||||
103 | substr(${ *$self->{Buffer} }, $offset, length($data)) = $data ; | ||||
104 | } | ||||
105 | |||||
106 | return 1; | ||||
107 | } | ||||
108 | |||||
109 | sub output | ||||
110 | { | ||||
111 | my $self = shift ; | ||||
112 | my $data = shift ; | ||||
113 | my $last = shift ; | ||||
114 | |||||
115 | return 1 | ||||
116 | if length $data == 0 && ! $last ; | ||||
117 | |||||
118 | if ( *$self->{FilterEnvelope} ) { | ||||
119 | *_ = \$data; | ||||
120 | &{ *$self->{FilterEnvelope} }(); | ||||
121 | } | ||||
122 | |||||
123 | if (length $data) { | ||||
124 | if ( defined *$self->{FH} ) { | ||||
125 | defined *$self->{FH}->write( $data, length $data ) | ||||
126 | or return $self->saveErrorString(0, $!, $!); | ||||
127 | } | ||||
128 | else { | ||||
129 | ${ *$self->{Buffer} } .= $data ; | ||||
130 | } | ||||
131 | } | ||||
132 | |||||
133 | return 1; | ||||
134 | } | ||||
135 | |||||
136 | sub getOneShotParams | ||||
137 | { | ||||
138 | return ( 'MultiStream' => [1, 1, Parse_boolean, 1], | ||||
139 | ); | ||||
140 | } | ||||
141 | |||||
142 | sub checkParams | ||||
143 | { | ||||
144 | my $self = shift ; | ||||
145 | my $class = shift ; | ||||
146 | |||||
147 | my $got = shift || IO::Compress::Base::Parameters::new(); | ||||
148 | |||||
149 | $got->parse( | ||||
150 | { | ||||
151 | # Generic Parameters | ||||
152 | 'AutoClose' => [1, 1, Parse_boolean, 0], | ||||
153 | #'Encode' => [1, 1, Parse_any, undef], | ||||
154 | 'Strict' => [0, 1, Parse_boolean, 1], | ||||
155 | 'Append' => [1, 1, Parse_boolean, 0], | ||||
156 | 'BinModeIn' => [1, 1, Parse_boolean, 0], | ||||
157 | |||||
158 | 'FilterEnvelope' => [1, 1, Parse_any, undef], | ||||
159 | |||||
160 | $self->getExtraParams(), | ||||
161 | *$self->{OneShot} ? $self->getOneShotParams() | ||||
162 | : (), | ||||
163 | }, | ||||
164 | @_) or $self->croakError("${class}: $got->{Error}") ; | ||||
165 | |||||
166 | return $got ; | ||||
167 | } | ||||
168 | |||||
169 | sub _create | ||||
170 | { | ||||
171 | my $obj = shift; | ||||
172 | my $got = shift; | ||||
173 | |||||
174 | *$obj->{Closed} = 1 ; | ||||
175 | |||||
176 | my $class = ref $obj; | ||||
177 | $obj->croakError("$class: Missing Output parameter") | ||||
178 | if ! @_ && ! $got ; | ||||
179 | |||||
180 | my $outValue = shift ; | ||||
181 | my $oneShot = 1 ; | ||||
182 | |||||
183 | if (! $got) | ||||
184 | { | ||||
185 | $oneShot = 0 ; | ||||
186 | $got = $obj->checkParams($class, undef, @_) | ||||
187 | or return undef ; | ||||
188 | } | ||||
189 | |||||
190 | my $lax = ! $got->value('Strict') ; | ||||
191 | |||||
192 | my $outType = whatIsOutput($outValue); | ||||
193 | |||||
194 | $obj->ckOutputParam($class, $outValue) | ||||
195 | or return undef ; | ||||
196 | |||||
197 | if ($outType eq 'buffer') { | ||||
198 | *$obj->{Buffer} = $outValue; | ||||
199 | } | ||||
200 | else { | ||||
201 | my $buff = "" ; | ||||
202 | *$obj->{Buffer} = \$buff ; | ||||
203 | } | ||||
204 | |||||
205 | # Merge implies Append | ||||
206 | my $merge = $got->value('Merge') ; | ||||
207 | my $appendOutput = $got->value('Append') || $merge ; | ||||
208 | *$obj->{Append} = $appendOutput; | ||||
209 | *$obj->{FilterEnvelope} = $got->value('FilterEnvelope') ; | ||||
210 | |||||
211 | if ($merge) | ||||
212 | { | ||||
213 | # Switch off Merge mode if output file/buffer is empty/doesn't exist | ||||
214 | if (($outType eq 'buffer' && length $$outValue == 0 ) || | ||||
215 | ($outType ne 'buffer' && (! -e $outValue || (-w _ && -z _))) ) | ||||
216 | { $merge = 0 } | ||||
217 | } | ||||
218 | |||||
219 | # If output is a file, check that it is writable | ||||
220 | #no warnings; | ||||
221 | #if ($outType eq 'filename' && -e $outValue && ! -w _) | ||||
222 | # { return $obj->saveErrorString(undef, "Output file '$outValue' is not writable" ) } | ||||
223 | |||||
- - | |||||
226 | if ($got->parsed('Encode')) { | ||||
227 | my $want_encoding = $got->value('Encode'); | ||||
228 | *$obj->{Encoding} = getEncoding($obj, $class, $want_encoding); | ||||
229 | } | ||||
230 | |||||
231 | $obj->ckParams($got) | ||||
232 | or $obj->croakError("${class}: " . $obj->error()); | ||||
233 | |||||
234 | |||||
235 | $obj->saveStatus(STATUS_OK) ; | ||||
236 | |||||
237 | my $status ; | ||||
238 | if (! $merge) | ||||
239 | { | ||||
240 | *$obj->{Compress} = $obj->mkComp($got) | ||||
241 | or return undef; | ||||
242 | |||||
243 | *$obj->{UnCompSize} = new U64 ; | ||||
244 | *$obj->{CompSize} = new U64 ; | ||||
245 | |||||
246 | if ( $outType eq 'buffer') { | ||||
247 | ${ *$obj->{Buffer} } = '' | ||||
248 | unless $appendOutput ; | ||||
249 | } | ||||
250 | else { | ||||
251 | if ($outType eq 'handle') { | ||||
252 | *$obj->{FH} = $outValue ; | ||||
253 | setBinModeOutput(*$obj->{FH}) ; | ||||
254 | $outValue->flush() ; | ||||
255 | *$obj->{Handle} = 1 ; | ||||
256 | if ($appendOutput) | ||||
257 | { | ||||
258 | seek(*$obj->{FH}, 0, SEEK_END) | ||||
259 | or return $obj->saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ; | ||||
260 | |||||
261 | } | ||||
262 | } | ||||
263 | elsif ($outType eq 'filename') { | ||||
264 | 3 | 2.55ms | 2 | 60µs | # spent 37µs (15+22) within IO::Compress::Base::BEGIN@264 which was called:
# once (15µs+22µs) by IO::Compress::RawDeflate::BEGIN@10 at line 264 # spent 37µs making 1 call to IO::Compress::Base::BEGIN@264
# spent 22µs making 1 call to warnings::unimport |
265 | my $mode = '>' ; | ||||
266 | $mode = '>>' | ||||
267 | if $appendOutput; | ||||
268 | *$obj->{FH} = new IO::File "$mode $outValue" | ||||
269 | or return $obj->saveErrorString(undef, "cannot open file '$outValue': $!", $!) ; | ||||
270 | *$obj->{StdIO} = ($outValue eq '-'); | ||||
271 | setBinModeOutput(*$obj->{FH}) ; | ||||
272 | } | ||||
273 | } | ||||
274 | |||||
275 | *$obj->{Header} = $obj->mkHeader($got) ; | ||||
276 | $obj->output( *$obj->{Header} ) | ||||
277 | or return undef; | ||||
278 | } | ||||
279 | else | ||||
280 | { | ||||
281 | *$obj->{Compress} = $obj->createMerge($outValue, $outType) | ||||
282 | or return undef; | ||||
283 | } | ||||
284 | |||||
285 | *$obj->{Closed} = 0 ; | ||||
286 | *$obj->{AutoClose} = $got->value('AutoClose') ; | ||||
287 | *$obj->{Output} = $outValue; | ||||
288 | *$obj->{ClassName} = $class; | ||||
289 | *$obj->{Got} = $got; | ||||
290 | *$obj->{OneShot} = 0 ; | ||||
291 | |||||
292 | return $obj ; | ||||
293 | } | ||||
294 | |||||
295 | sub ckOutputParam | ||||
296 | { | ||||
297 | my $self = shift ; | ||||
298 | my $from = shift ; | ||||
299 | my $outType = whatIsOutput($_[0]); | ||||
300 | |||||
301 | $self->croakError("$from: output parameter not a filename, filehandle or scalar ref") | ||||
302 | if ! $outType ; | ||||
303 | |||||
304 | #$self->croakError("$from: output filename is undef or null string") | ||||
305 | #if $outType eq 'filename' && (! defined $_[0] || $_[0] eq '') ; | ||||
306 | |||||
307 | $self->croakError("$from: output buffer is read-only") | ||||
308 | if $outType eq 'buffer' && readonly(${ $_[0] }); | ||||
309 | |||||
310 | return 1; | ||||
311 | } | ||||
312 | |||||
313 | |||||
314 | sub _def | ||||
315 | { | ||||
316 | my $obj = shift ; | ||||
317 | |||||
318 | my $class= (caller)[0] ; | ||||
319 | my $name = (caller(1))[3] ; | ||||
320 | |||||
321 | $obj->croakError("$name: expected at least 1 parameters\n") | ||||
322 | unless @_ >= 1 ; | ||||
323 | |||||
324 | my $input = shift ; | ||||
325 | my $haveOut = @_ ; | ||||
326 | my $output = shift ; | ||||
327 | |||||
328 | my $x = new IO::Compress::Base::Validator($class, *$obj->{Error}, $name, $input, $output) | ||||
329 | or return undef ; | ||||
330 | |||||
331 | push @_, $output if $haveOut && $x->{Hash}; | ||||
332 | |||||
333 | *$obj->{OneShot} = 1 ; | ||||
334 | |||||
335 | my $got = $obj->checkParams($name, undef, @_) | ||||
336 | or return undef ; | ||||
337 | |||||
338 | $x->{Got} = $got ; | ||||
339 | |||||
340 | # if ($x->{Hash}) | ||||
341 | # { | ||||
342 | # while (my($k, $v) = each %$input) | ||||
343 | # { | ||||
344 | # $v = \$input->{$k} | ||||
345 | # unless defined $v ; | ||||
346 | # | ||||
347 | # $obj->_singleTarget($x, 1, $k, $v, @_) | ||||
348 | # or return undef ; | ||||
349 | # } | ||||
350 | # | ||||
351 | # return keys %$input ; | ||||
352 | # } | ||||
353 | |||||
354 | if ($x->{GlobMap}) | ||||
355 | { | ||||
356 | $x->{oneInput} = 1 ; | ||||
357 | foreach my $pair (@{ $x->{Pairs} }) | ||||
358 | { | ||||
359 | my ($from, $to) = @$pair ; | ||||
360 | $obj->_singleTarget($x, 1, $from, $to, @_) | ||||
361 | or return undef ; | ||||
362 | } | ||||
363 | |||||
364 | return scalar @{ $x->{Pairs} } ; | ||||
365 | } | ||||
366 | |||||
367 | if (! $x->{oneOutput} ) | ||||
368 | { | ||||
369 | my $inFile = ($x->{inType} eq 'filenames' | ||||
370 | || $x->{inType} eq 'filename'); | ||||
371 | |||||
372 | $x->{inType} = $inFile ? 'filename' : 'buffer'; | ||||
373 | |||||
374 | foreach my $in ($x->{oneInput} ? $input : @$input) | ||||
375 | { | ||||
376 | my $out ; | ||||
377 | $x->{oneInput} = 1 ; | ||||
378 | |||||
379 | $obj->_singleTarget($x, $inFile, $in, \$out, @_) | ||||
380 | or return undef ; | ||||
381 | |||||
382 | push @$output, \$out ; | ||||
383 | #if ($x->{outType} eq 'array') | ||||
384 | # { push @$output, \$out } | ||||
385 | #else | ||||
386 | # { $output->{$in} = \$out } | ||||
387 | } | ||||
388 | |||||
389 | return 1 ; | ||||
390 | } | ||||
391 | |||||
392 | # finally the 1 to 1 and n to 1 | ||||
393 | return $obj->_singleTarget($x, 1, $input, $output, @_); | ||||
394 | |||||
395 | croak "should not be here" ; | ||||
396 | } | ||||
397 | |||||
398 | sub _singleTarget | ||||
399 | { | ||||
400 | my $obj = shift ; | ||||
401 | my $x = shift ; | ||||
402 | my $inputIsFilename = shift; | ||||
403 | my $input = shift; | ||||
404 | |||||
405 | if ($x->{oneInput}) | ||||
406 | { | ||||
407 | $obj->getFileInfo($x->{Got}, $input) | ||||
408 | if isaFilename($input) and $inputIsFilename ; | ||||
409 | |||||
410 | my $z = $obj->_create($x->{Got}, @_) | ||||
411 | or return undef ; | ||||
412 | |||||
413 | |||||
414 | defined $z->_wr2($input, $inputIsFilename) | ||||
415 | or return $z->closeError(undef) ; | ||||
416 | |||||
417 | return $z->close() ; | ||||
418 | } | ||||
419 | else | ||||
420 | { | ||||
421 | my $afterFirst = 0 ; | ||||
422 | my $inputIsFilename = ($x->{inType} ne 'array'); | ||||
423 | my $keep = $x->{Got}->clone(); | ||||
424 | |||||
425 | #for my $element ( ($x->{inType} eq 'hash') ? keys %$input : @$input) | ||||
426 | for my $element ( @$input) | ||||
427 | { | ||||
428 | my $isFilename = isaFilename($element); | ||||
429 | |||||
430 | if ( $afterFirst ++ ) | ||||
431 | { | ||||
432 | defined addInterStream($obj, $element, $isFilename) | ||||
433 | or return $obj->closeError(undef) ; | ||||
434 | } | ||||
435 | else | ||||
436 | { | ||||
437 | $obj->getFileInfo($x->{Got}, $element) | ||||
438 | if $isFilename; | ||||
439 | |||||
440 | $obj->_create($x->{Got}, @_) | ||||
441 | or return undef ; | ||||
442 | } | ||||
443 | |||||
444 | defined $obj->_wr2($element, $isFilename) | ||||
445 | or return $obj->closeError(undef) ; | ||||
446 | |||||
447 | *$obj->{Got} = $keep->clone(); | ||||
448 | } | ||||
449 | return $obj->close() ; | ||||
450 | } | ||||
451 | |||||
452 | } | ||||
453 | |||||
454 | sub _wr2 | ||||
455 | { | ||||
456 | my $self = shift ; | ||||
457 | |||||
458 | my $source = shift ; | ||||
459 | my $inputIsFilename = shift; | ||||
460 | |||||
461 | my $input = $source ; | ||||
462 | if (! $inputIsFilename) | ||||
463 | { | ||||
464 | $input = \$source | ||||
465 | if ! ref $source; | ||||
466 | } | ||||
467 | |||||
468 | if ( ref $input && ref $input eq 'SCALAR' ) | ||||
469 | { | ||||
470 | return $self->syswrite($input, @_) ; | ||||
471 | } | ||||
472 | |||||
473 | if ( ! ref $input || isaFilehandle($input)) | ||||
474 | { | ||||
475 | my $isFilehandle = isaFilehandle($input) ; | ||||
476 | |||||
477 | my $fh = $input ; | ||||
478 | |||||
479 | if ( ! $isFilehandle ) | ||||
480 | { | ||||
481 | $fh = new IO::File "<$input" | ||||
482 | or return $self->saveErrorString(undef, "cannot open file '$input': $!", $!) ; | ||||
483 | } | ||||
484 | binmode $fh if *$self->{Got}->valueOrDefault('BinModeIn') ; | ||||
485 | |||||
486 | my $status ; | ||||
487 | my $buff ; | ||||
488 | my $count = 0 ; | ||||
489 | while (($status = read($fh, $buff, 16 * 1024)) > 0) { | ||||
490 | $count += length $buff; | ||||
491 | defined $self->syswrite($buff, @_) | ||||
492 | or return undef ; | ||||
493 | } | ||||
494 | |||||
495 | return $self->saveErrorString(undef, $!, $!) | ||||
496 | if $status < 0 ; | ||||
497 | |||||
498 | if ( (!$isFilehandle || *$self->{AutoClose}) && $input ne '-') | ||||
499 | { | ||||
500 | $fh->close() | ||||
501 | or return undef ; | ||||
502 | } | ||||
503 | |||||
504 | return $count ; | ||||
505 | } | ||||
506 | |||||
507 | croak "Should not be here"; | ||||
508 | return undef; | ||||
509 | } | ||||
510 | |||||
511 | sub addInterStream | ||||
512 | { | ||||
513 | my $self = shift ; | ||||
514 | my $input = shift ; | ||||
515 | my $inputIsFilename = shift ; | ||||
516 | |||||
517 | if (*$self->{Got}->value('MultiStream')) | ||||
518 | { | ||||
519 | $self->getFileInfo(*$self->{Got}, $input) | ||||
520 | #if isaFilename($input) and $inputIsFilename ; | ||||
521 | if isaFilename($input) ; | ||||
522 | |||||
523 | # TODO -- newStream needs to allow gzip/zip header to be modified | ||||
524 | return $self->newStream(); | ||||
525 | } | ||||
526 | elsif (*$self->{Got}->value('AutoFlush')) | ||||
527 | { | ||||
528 | #return $self->flush(Z_FULL_FLUSH); | ||||
529 | } | ||||
530 | |||||
531 | return 1 ; | ||||
532 | } | ||||
533 | |||||
534 | sub getFileInfo | ||||
535 | { | ||||
536 | } | ||||
537 | |||||
538 | sub TIEHANDLE | ||||
539 | { | ||||
540 | return $_[0] if ref($_[0]); | ||||
541 | die "OOPS\n" ; | ||||
542 | } | ||||
543 | |||||
544 | sub UNTIE | ||||
545 | { | ||||
546 | my $self = shift ; | ||||
547 | } | ||||
548 | |||||
549 | sub DESTROY | ||||
550 | { | ||||
551 | my $self = shift ; | ||||
552 | local ($., $@, $!, $^E, $?); | ||||
553 | |||||
554 | $self->close() ; | ||||
555 | |||||
556 | # TODO - memory leak with 5.8.0 - this isn't called until | ||||
557 | # global destruction | ||||
558 | # | ||||
559 | %{ *$self } = () ; | ||||
560 | undef $self ; | ||||
561 | } | ||||
562 | |||||
- - | |||||
565 | sub filterUncompressed | ||||
566 | { | ||||
567 | } | ||||
568 | |||||
569 | sub syswrite | ||||
570 | { | ||||
571 | my $self = shift ; | ||||
572 | |||||
573 | my $buffer ; | ||||
574 | if (ref $_[0] ) { | ||||
575 | $self->croakError( *$self->{ClassName} . "::write: not a scalar reference" ) | ||||
576 | unless ref $_[0] eq 'SCALAR' ; | ||||
577 | $buffer = $_[0] ; | ||||
578 | } | ||||
579 | else { | ||||
580 | $buffer = \$_[0] ; | ||||
581 | } | ||||
582 | |||||
583 | $] >= 5.008 and ( utf8::downgrade($$buffer, 1) | ||||
584 | or croak "Wide character in " . *$self->{ClassName} . "::write:"); | ||||
585 | |||||
586 | |||||
587 | if (@_ > 1) { | ||||
588 | my $slen = defined $$buffer ? length($$buffer) : 0; | ||||
589 | my $len = $slen; | ||||
590 | my $offset = 0; | ||||
591 | $len = $_[1] if $_[1] < $len; | ||||
592 | |||||
593 | if (@_ > 2) { | ||||
594 | $offset = $_[2] || 0; | ||||
595 | $self->croakError(*$self->{ClassName} . "::write: offset outside string") | ||||
596 | if $offset > $slen; | ||||
597 | if ($offset < 0) { | ||||
598 | $offset += $slen; | ||||
599 | $self->croakError( *$self->{ClassName} . "::write: offset outside string") if $offset < 0; | ||||
600 | } | ||||
601 | my $rem = $slen - $offset; | ||||
602 | $len = $rem if $rem < $len; | ||||
603 | } | ||||
604 | |||||
605 | $buffer = \substr($$buffer, $offset, $len) ; | ||||
606 | } | ||||
607 | |||||
608 | return 0 if ! defined $$buffer || length $$buffer == 0 ; | ||||
609 | |||||
610 | if (*$self->{Encoding}) { | ||||
611 | $$buffer = *$self->{Encoding}->encode($$buffer); | ||||
612 | } | ||||
613 | |||||
614 | $self->filterUncompressed($buffer); | ||||
615 | |||||
616 | my $buffer_length = defined $$buffer ? length($$buffer) : 0 ; | ||||
617 | *$self->{UnCompSize}->add($buffer_length) ; | ||||
618 | |||||
619 | my $outBuffer=''; | ||||
620 | my $status = *$self->{Compress}->compr($buffer, $outBuffer) ; | ||||
621 | |||||
622 | return $self->saveErrorString(undef, *$self->{Compress}{Error}, | ||||
623 | *$self->{Compress}{ErrorNo}) | ||||
624 | if $status == STATUS_ERROR; | ||||
625 | |||||
626 | *$self->{CompSize}->add(length $outBuffer) ; | ||||
627 | |||||
628 | $self->output($outBuffer) | ||||
629 | or return undef; | ||||
630 | |||||
631 | return $buffer_length; | ||||
632 | } | ||||
633 | |||||
634 | sub print | ||||
635 | { | ||||
636 | my $self = shift; | ||||
637 | |||||
638 | #if (ref $self) { | ||||
639 | # $self = *$self{GLOB} ; | ||||
640 | #} | ||||
641 | |||||
642 | if (defined $\) { | ||||
643 | if (defined $,) { | ||||
644 | defined $self->syswrite(join($,, @_) . $\); | ||||
645 | } else { | ||||
646 | defined $self->syswrite(join("", @_) . $\); | ||||
647 | } | ||||
648 | } else { | ||||
649 | if (defined $,) { | ||||
650 | defined $self->syswrite(join($,, @_)); | ||||
651 | } else { | ||||
652 | defined $self->syswrite(join("", @_)); | ||||
653 | } | ||||
654 | } | ||||
655 | } | ||||
656 | |||||
657 | sub printf | ||||
658 | { | ||||
659 | my $self = shift; | ||||
660 | my $fmt = shift; | ||||
661 | defined $self->syswrite(sprintf($fmt, @_)); | ||||
662 | } | ||||
663 | |||||
- - | |||||
666 | sub flush | ||||
667 | { | ||||
668 | my $self = shift ; | ||||
669 | |||||
670 | my $outBuffer=''; | ||||
671 | my $status = *$self->{Compress}->flush($outBuffer, @_) ; | ||||
672 | return $self->saveErrorString(0, *$self->{Compress}{Error}, | ||||
673 | *$self->{Compress}{ErrorNo}) | ||||
674 | if $status == STATUS_ERROR; | ||||
675 | |||||
676 | if ( defined *$self->{FH} ) { | ||||
677 | *$self->{FH}->clearerr(); | ||||
678 | } | ||||
679 | |||||
680 | *$self->{CompSize}->add(length $outBuffer) ; | ||||
681 | |||||
682 | $self->output($outBuffer) | ||||
683 | or return 0; | ||||
684 | |||||
685 | if ( defined *$self->{FH} ) { | ||||
686 | defined *$self->{FH}->flush() | ||||
687 | or return $self->saveErrorString(0, $!, $!); | ||||
688 | } | ||||
689 | |||||
690 | return 1; | ||||
691 | } | ||||
692 | |||||
693 | sub newStream | ||||
694 | { | ||||
695 | my $self = shift ; | ||||
696 | |||||
697 | $self->_writeTrailer() | ||||
698 | or return 0 ; | ||||
699 | |||||
700 | my $got = $self->checkParams('newStream', *$self->{Got}, @_) | ||||
701 | or return 0 ; | ||||
702 | |||||
703 | $self->ckParams($got) | ||||
704 | or $self->croakError("newStream: $self->{Error}"); | ||||
705 | |||||
706 | *$self->{Compress} = $self->mkComp($got) | ||||
707 | or return 0; | ||||
708 | |||||
709 | *$self->{Header} = $self->mkHeader($got) ; | ||||
710 | $self->output(*$self->{Header} ) | ||||
711 | or return 0; | ||||
712 | |||||
713 | *$self->{UnCompSize}->reset(); | ||||
714 | *$self->{CompSize}->reset(); | ||||
715 | |||||
716 | return 1 ; | ||||
717 | } | ||||
718 | |||||
719 | sub reset | ||||
720 | { | ||||
721 | my $self = shift ; | ||||
722 | return *$self->{Compress}->reset() ; | ||||
723 | } | ||||
724 | |||||
725 | sub _writeTrailer | ||||
726 | { | ||||
727 | my $self = shift ; | ||||
728 | |||||
729 | my $trailer = ''; | ||||
730 | |||||
731 | my $status = *$self->{Compress}->close($trailer) ; | ||||
732 | return $self->saveErrorString(0, *$self->{Compress}{Error}, *$self->{Compress}{ErrorNo}) | ||||
733 | if $status == STATUS_ERROR; | ||||
734 | |||||
735 | *$self->{CompSize}->add(length $trailer) ; | ||||
736 | |||||
737 | $trailer .= $self->mkTrailer(); | ||||
738 | defined $trailer | ||||
739 | or return 0; | ||||
740 | |||||
741 | return $self->output($trailer); | ||||
742 | } | ||||
743 | |||||
744 | sub _writeFinalTrailer | ||||
745 | { | ||||
746 | my $self = shift ; | ||||
747 | |||||
748 | return $self->output($self->mkFinalTrailer()); | ||||
749 | } | ||||
750 | |||||
751 | sub close | ||||
752 | { | ||||
753 | my $self = shift ; | ||||
754 | |||||
755 | return 1 if *$self->{Closed} || ! *$self->{Compress} ; | ||||
756 | *$self->{Closed} = 1 ; | ||||
757 | |||||
758 | untie *$self | ||||
759 | if $] >= 5.008 ; | ||||
760 | |||||
761 | $self->_writeTrailer() | ||||
762 | or return 0 ; | ||||
763 | |||||
764 | $self->_writeFinalTrailer() | ||||
765 | or return 0 ; | ||||
766 | |||||
767 | $self->output( "", 1 ) | ||||
768 | or return 0; | ||||
769 | |||||
770 | if (defined *$self->{FH}) { | ||||
771 | |||||
772 | #if (! *$self->{Handle} || *$self->{AutoClose}) { | ||||
773 | if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) { | ||||
774 | $! = 0 ; | ||||
775 | *$self->{FH}->close() | ||||
776 | or return $self->saveErrorString(0, $!, $!); | ||||
777 | } | ||||
778 | delete *$self->{FH} ; | ||||
779 | # This delete can set $! in older Perls, so reset the errno | ||||
780 | $! = 0 ; | ||||
781 | } | ||||
782 | |||||
783 | return 1; | ||||
784 | } | ||||
785 | |||||
786 | |||||
787 | #sub total_in | ||||
788 | #sub total_out | ||||
789 | #sub msg | ||||
790 | # | ||||
791 | #sub crc | ||||
792 | #{ | ||||
793 | # my $self = shift ; | ||||
794 | # return *$self->{Compress}->crc32() ; | ||||
795 | #} | ||||
796 | # | ||||
797 | #sub msg | ||||
798 | #{ | ||||
799 | # my $self = shift ; | ||||
800 | # return *$self->{Compress}->msg() ; | ||||
801 | #} | ||||
802 | # | ||||
803 | #sub dict_adler | ||||
804 | #{ | ||||
805 | # my $self = shift ; | ||||
806 | # return *$self->{Compress}->dict_adler() ; | ||||
807 | #} | ||||
808 | # | ||||
809 | #sub get_Level | ||||
810 | #{ | ||||
811 | # my $self = shift ; | ||||
812 | # return *$self->{Compress}->get_Level() ; | ||||
813 | #} | ||||
814 | # | ||||
815 | #sub get_Strategy | ||||
816 | #{ | ||||
817 | # my $self = shift ; | ||||
818 | # return *$self->{Compress}->get_Strategy() ; | ||||
819 | #} | ||||
820 | |||||
821 | |||||
822 | sub tell | ||||
823 | { | ||||
824 | my $self = shift ; | ||||
825 | |||||
826 | return *$self->{UnCompSize}->get32bit() ; | ||||
827 | } | ||||
828 | |||||
829 | sub eof | ||||
830 | { | ||||
831 | my $self = shift ; | ||||
832 | |||||
833 | return *$self->{Closed} ; | ||||
834 | } | ||||
835 | |||||
836 | |||||
837 | sub seek | ||||
838 | { | ||||
839 | my $self = shift ; | ||||
840 | my $position = shift; | ||||
841 | my $whence = shift ; | ||||
842 | |||||
843 | my $here = $self->tell() ; | ||||
844 | my $target = 0 ; | ||||
845 | |||||
846 | #use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END); | ||||
847 | 3 | 547µs | 2 | 80µs | # spent 48µs (16+32) within IO::Compress::Base::BEGIN@847 which was called:
# once (16µs+32µs) by IO::Compress::RawDeflate::BEGIN@10 at line 847 # spent 48µs making 1 call to IO::Compress::Base::BEGIN@847
# spent 32µs making 1 call to Exporter::import |
848 | |||||
849 | if ($whence == IO::Handle::SEEK_SET) { | ||||
850 | $target = $position ; | ||||
851 | } | ||||
852 | elsif ($whence == IO::Handle::SEEK_CUR || $whence == IO::Handle::SEEK_END) { | ||||
853 | $target = $here + $position ; | ||||
854 | } | ||||
855 | else { | ||||
856 | $self->croakError(*$self->{ClassName} . "::seek: unknown value, $whence, for whence parameter"); | ||||
857 | } | ||||
858 | |||||
859 | # short circuit if seeking to current offset | ||||
860 | return 1 if $target == $here ; | ||||
861 | |||||
862 | # Outlaw any attempt to seek backwards | ||||
863 | $self->croakError(*$self->{ClassName} . "::seek: cannot seek backwards") | ||||
864 | if $target < $here ; | ||||
865 | |||||
866 | # Walk the file to the new offset | ||||
867 | my $offset = $target - $here ; | ||||
868 | |||||
869 | my $buffer ; | ||||
870 | defined $self->syswrite("\x00" x $offset) | ||||
871 | or return 0; | ||||
872 | |||||
873 | return 1 ; | ||||
874 | } | ||||
875 | |||||
876 | sub binmode | ||||
877 | { | ||||
878 | 1; | ||||
879 | # my $self = shift ; | ||||
880 | # return defined *$self->{FH} | ||||
881 | # ? binmode *$self->{FH} | ||||
882 | # : 1 ; | ||||
883 | } | ||||
884 | |||||
885 | sub fileno | ||||
886 | { | ||||
887 | my $self = shift ; | ||||
888 | return defined *$self->{FH} | ||||
889 | ? *$self->{FH}->fileno() | ||||
890 | : undef ; | ||||
891 | } | ||||
892 | |||||
893 | sub opened | ||||
894 | { | ||||
895 | my $self = shift ; | ||||
896 | return ! *$self->{Closed} ; | ||||
897 | } | ||||
898 | |||||
899 | sub autoflush | ||||
900 | { | ||||
901 | my $self = shift ; | ||||
902 | return defined *$self->{FH} | ||||
903 | ? *$self->{FH}->autoflush(@_) | ||||
904 | : undef ; | ||||
905 | } | ||||
906 | |||||
907 | sub input_line_number | ||||
908 | { | ||||
909 | return undef ; | ||||
910 | } | ||||
911 | |||||
912 | |||||
913 | sub _notAvailable | ||||
914 | # spent 21µs within IO::Compress::Base::_notAvailable which was called 6 times, avg 4µs/call:
# once (6µs+0s) by IO::Compress::RawDeflate::BEGIN@10 at line 919
# once (4µs+0s) by IO::Compress::RawDeflate::BEGIN@10 at line 923
# once (3µs+0s) by IO::Compress::RawDeflate::BEGIN@10 at line 920
# once (3µs+0s) by IO::Compress::RawDeflate::BEGIN@10 at line 924
# once (3µs+0s) by IO::Compress::RawDeflate::BEGIN@10 at line 921
# once (3µs+0s) by IO::Compress::RawDeflate::BEGIN@10 at line 922 | ||||
915 | 12 | 39µs | my $name = shift ; | ||
916 | return sub { croak "$name Not Available: File opened only for output" ; } ; | ||||
917 | } | ||||
918 | |||||
919 | 1 | 4µs | 1 | 6µs | *read = _notAvailable('read'); # spent 6µs making 1 call to IO::Compress::Base::_notAvailable |
920 | 1 | 2µs | 1 | 3µs | *READ = _notAvailable('read'); # spent 3µs making 1 call to IO::Compress::Base::_notAvailable |
921 | 1 | 2µs | 1 | 3µs | *readline = _notAvailable('readline'); # spent 3µs making 1 call to IO::Compress::Base::_notAvailable |
922 | 1 | 2µs | 1 | 3µs | *READLINE = _notAvailable('readline'); # spent 3µs making 1 call to IO::Compress::Base::_notAvailable |
923 | 1 | 2µs | 1 | 4µs | *getc = _notAvailable('getc'); # spent 4µs making 1 call to IO::Compress::Base::_notAvailable |
924 | 1 | 2µs | 1 | 3µs | *GETC = _notAvailable('getc'); # spent 3µs making 1 call to IO::Compress::Base::_notAvailable |
925 | |||||
926 | 1 | 800ns | *FILENO = \&fileno; | ||
927 | 1 | 700ns | *PRINT = \&print; | ||
928 | 1 | 400ns | *PRINTF = \&printf; | ||
929 | 1 | 500ns | *WRITE = \&syswrite; | ||
930 | 1 | 400ns | *write = \&syswrite; | ||
931 | 1 | 400ns | *SEEK = \&seek; | ||
932 | 1 | 600ns | *TELL = \&tell; | ||
933 | 1 | 500ns | *EOF = \&eof; | ||
934 | 1 | 500ns | *CLOSE = \&close; | ||
935 | 1 | 400ns | *BINMODE = \&binmode; | ||
936 | |||||
937 | #*sysread = \&_notAvailable; | ||||
938 | #*syswrite = \&_write; | ||||
939 | |||||
940 | 1 | 14µs | 1; | ||
941 | |||||
942 | __END__ |