Commit | Line | Data |
---|---|---|
642e522c RGS |
1 | package IO::Uncompress::AnyInflate ; |
2 | ||
3 | # for RFC1950, RFC1951 or RFC1952 | |
4 | ||
5 | use strict; | |
6 | use warnings; | |
a02d0f6f | 7 | use bytes; |
1a6a8453 | 8 | |
a02d0f6f | 9 | use IO::Compress::Base::Common qw(createSelfTiedObject); |
1a6a8453 | 10 | |
a02d0f6f | 11 | use IO::Uncompress::Adapter::Inflate (); |
1a6a8453 PM |
12 | |
13 | ||
a02d0f6f | 14 | use IO::Uncompress::Base ; |
642e522c | 15 | use IO::Uncompress::Gunzip ; |
1a6a8453 PM |
16 | use IO::Uncompress::Inflate ; |
17 | use IO::Uncompress::RawInflate ; | |
18 | use IO::Uncompress::Unzip ; | |
642e522c RGS |
19 | |
20 | require Exporter ; | |
21 | ||
22 | our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $AnyInflateError); | |
23 | ||
e7d45986 | 24 | $VERSION = '2.000_13'; |
642e522c RGS |
25 | $AnyInflateError = ''; |
26 | ||
1a6a8453 | 27 | @ISA = qw( Exporter IO::Uncompress::Base ); |
642e522c | 28 | @EXPORT_OK = qw( $AnyInflateError anyinflate ) ; |
1a6a8453 | 29 | %EXPORT_TAGS = %IO::Uncompress::Base::DEFLATE_CONSTANTS ; |
642e522c RGS |
30 | push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; |
31 | Exporter::export_ok_tags('all'); | |
32 | ||
642e522c RGS |
33 | # TODO - allow the user to pick a set of the three formats to allow |
34 | # or just assume want to auto-detect any of the three formats. | |
35 | ||
36 | sub new | |
37 | { | |
1a6a8453 PM |
38 | my $class = shift ; |
39 | my $obj = createSelfTiedObject($class, \$AnyInflateError); | |
40 | $obj->_create(undef, 0, @_); | |
642e522c RGS |
41 | } |
42 | ||
43 | sub anyinflate | |
44 | { | |
1a6a8453 PM |
45 | my $obj = createSelfTiedObject(undef, \$AnyInflateError); |
46 | return $obj->_inf(@_) ; | |
47 | } | |
48 | ||
49 | sub getExtraParams | |
50 | { | |
6ecef415 PM |
51 | use IO::Compress::Base::Common qw(:Parse); |
52 | return ( 'RawInflate' => [1, 1, Parse_boolean, 0] ) ; | |
1a6a8453 PM |
53 | } |
54 | ||
55 | sub ckParams | |
56 | { | |
57 | my $self = shift ; | |
58 | my $got = shift ; | |
59 | ||
60 | # any always needs both crc32 and adler32 | |
61 | $got->value('CRC32' => 1); | |
62 | $got->value('ADLER32' => 1); | |
63 | ||
64 | return 1; | |
65 | } | |
66 | ||
67 | sub mkUncomp | |
68 | { | |
69 | my $self = shift ; | |
70 | my $class = shift ; | |
71 | my $got = shift ; | |
72 | ||
a02d0f6f | 73 | my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject(); |
1a6a8453 PM |
74 | |
75 | return $self->saveErrorString(undef, $errstr, $errno) | |
76 | if ! defined $obj; | |
77 | ||
78 | *$self->{Uncomp} = $obj; | |
79 | ||
6ecef415 PM |
80 | my @possible = qw( Inflate Gunzip Unzip ); |
81 | unshift @possible, 'RawInflate' | |
82 | if 1 || $got->value('RawInflate'); | |
83 | ||
84 | my $magic = $self->ckMagic( @possible ); | |
1a6a8453 PM |
85 | |
86 | if ($magic) { | |
87 | *$self->{Info} = $self->readHeader($magic) | |
88 | or return undef ; | |
89 | ||
90 | return 1; | |
91 | } | |
92 | ||
93 | return 0 ; | |
94 | } | |
95 | ||
96 | ||
97 | ||
98 | sub ckMagic | |
99 | { | |
100 | my $self = shift; | |
101 | my @names = @_ ; | |
102 | ||
103 | my $keep = ref $self ; | |
104 | for my $class ( map { "IO::Uncompress::$_" } @names) | |
105 | { | |
106 | bless $self => $class; | |
107 | my $magic = $self->ckMagic(); | |
108 | ||
109 | if ($magic) | |
110 | { | |
111 | #bless $self => $class; | |
112 | return $magic ; | |
113 | } | |
114 | ||
115 | $self->pushBack(*$self->{HeaderPending}) ; | |
116 | *$self->{HeaderPending} = '' ; | |
117 | } | |
118 | ||
119 | bless $self => $keep; | |
120 | return undef; | |
642e522c RGS |
121 | } |
122 | ||
123 | 1 ; | |
124 | ||
125 | __END__ | |
126 | ||
127 | ||
128 | =head1 NAME | |
129 | ||
a02d0f6f | 130 | |
cb7abd7f | 131 | IO::Uncompress::AnyInflate - Uncompress zlib-based (zip, gzip) file/buffer |
642e522c | 132 | |
a02d0f6f | 133 | |
642e522c RGS |
134 | =head1 SYNOPSIS |
135 | ||
136 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
137 | ||
138 | my $status = anyinflate $input => $output [,OPTS] | |
139 | or die "anyinflate failed: $AnyInflateError\n"; | |
140 | ||
141 | my $z = new IO::Uncompress::AnyInflate $input [OPTS] | |
142 | or die "anyinflate failed: $AnyInflateError\n"; | |
143 | ||
144 | $status = $z->read($buffer) | |
145 | $status = $z->read($buffer, $length) | |
146 | $status = $z->read($buffer, $length, $offset) | |
147 | $line = $z->getline() | |
148 | $char = $z->getc() | |
149 | $char = $z->ungetc() | |
a02d0f6f RGS |
150 | $char = $z->opened() |
151 | ||
642e522c | 152 | $status = $z->inflateSync() |
a02d0f6f | 153 | |
e7d45986 PM |
154 | $data = $z->trailingData() |
155 | $status = $z->nextStream() | |
642e522c RGS |
156 | $data = $z->getHeaderInfo() |
157 | $z->tell() | |
158 | $z->seek($position, $whence) | |
159 | $z->binmode() | |
160 | $z->fileno() | |
161 | $z->eof() | |
162 | $z->close() | |
163 | ||
164 | $AnyInflateError ; | |
165 | ||
166 | # IO::File mode | |
167 | ||
168 | <$z> | |
169 | read($z, $buffer); | |
170 | read($z, $buffer, $length); | |
171 | read($z, $buffer, $length, $offset); | |
172 | tell($z) | |
173 | seek($z, $position, $whence) | |
174 | binmode($z) | |
175 | fileno($z) | |
176 | eof($z) | |
177 | close($z) | |
178 | ||
179 | ||
180 | =head1 DESCRIPTION | |
181 | ||
182 | ||
183 | ||
184 | B<WARNING -- This is a Beta release>. | |
185 | ||
186 | =over 5 | |
187 | ||
188 | =item * DO NOT use in production code. | |
189 | ||
190 | =item * The documentation is incomplete in places. | |
191 | ||
192 | =item * Parts of the interface defined here are tentative. | |
193 | ||
194 | =item * Please report any problems you find. | |
195 | ||
196 | =back | |
197 | ||
198 | ||
199 | ||
200 | ||
1a6a8453 | 201 | This module provides a Perl interface that allows the reading of |
cb7abd7f PM |
202 | files/buffers that have been compressed in a number of formats that use the |
203 | zlib compression library. | |
204 | ||
205 | The formats supported are | |
206 | ||
207 | =over 5 | |
208 | ||
209 | =item RFC 1950 | |
210 | ||
211 | =item RFC 1951 | |
212 | ||
213 | =item gzip (RFC 1952) | |
214 | ||
215 | =item zip | |
642e522c | 216 | |
cb7abd7f PM |
217 | =back |
218 | ||
219 | The module will auto-detect which, if any, of the supported | |
1a6a8453 | 220 | compression formats is being used. |
642e522c RGS |
221 | |
222 | ||
223 | ||
cb7abd7f PM |
224 | |
225 | ||
226 | ||
642e522c RGS |
227 | =head1 Functional Interface |
228 | ||
1a6a8453 PM |
229 | A top-level function, C<anyinflate>, is provided to carry out |
230 | "one-shot" uncompression between buffers and/or files. For finer | |
231 | control over the uncompression process, see the L</"OO Interface"> | |
232 | section. | |
642e522c RGS |
233 | |
234 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
235 | ||
236 | anyinflate $input => $output [,OPTS] | |
237 | or die "anyinflate failed: $AnyInflateError\n"; | |
238 | ||
1a6a8453 | 239 | |
642e522c RGS |
240 | |
241 | The functional interface needs Perl5.005 or better. | |
242 | ||
243 | ||
244 | =head2 anyinflate $input => $output [, OPTS] | |
245 | ||
1a6a8453 PM |
246 | |
247 | C<anyinflate> expects at least two parameters, C<$input> and C<$output>. | |
642e522c RGS |
248 | |
249 | =head3 The C<$input> parameter | |
250 | ||
251 | The parameter, C<$input>, is used to define the source of | |
252 | the compressed data. | |
253 | ||
254 | It can take one of the following forms: | |
255 | ||
256 | =over 5 | |
257 | ||
258 | =item A filename | |
259 | ||
260 | If the C<$input> parameter is a simple scalar, it is assumed to be a | |
261 | filename. This file will be opened for reading and the input data | |
262 | will be read from it. | |
263 | ||
264 | =item A filehandle | |
265 | ||
266 | If the C<$input> parameter is a filehandle, the input data will be | |
267 | read from it. | |
268 | The string '-' can be used as an alias for standard input. | |
269 | ||
270 | =item A scalar reference | |
271 | ||
272 | If C<$input> is a scalar reference, the input data will be read | |
273 | from C<$$input>. | |
274 | ||
275 | =item An array reference | |
276 | ||
1a6a8453 PM |
277 | If C<$input> is an array reference, each element in the array must be a |
278 | filename. | |
279 | ||
280 | The input data will be read from each file in turn. | |
281 | ||
642e522c | 282 | The complete array will be walked to ensure that it only |
1a6a8453 PM |
283 | contains valid filenames before any data is uncompressed. |
284 | ||
285 | ||
642e522c RGS |
286 | |
287 | =item An Input FileGlob string | |
288 | ||
289 | If C<$input> is a string that is delimited by the characters "<" and ">" | |
290 | C<anyinflate> will assume that it is an I<input fileglob string>. The | |
291 | input is the list of files that match the fileglob. | |
292 | ||
293 | If the fileglob does not match any files ... | |
294 | ||
295 | See L<File::GlobMapper|File::GlobMapper> for more details. | |
296 | ||
297 | ||
298 | =back | |
299 | ||
300 | If the C<$input> parameter is any other type, C<undef> will be returned. | |
301 | ||
302 | ||
303 | ||
304 | =head3 The C<$output> parameter | |
305 | ||
306 | The parameter C<$output> is used to control the destination of the | |
307 | uncompressed data. This parameter can take one of these forms. | |
308 | ||
309 | =over 5 | |
310 | ||
311 | =item A filename | |
312 | ||
1a6a8453 PM |
313 | If the C<$output> parameter is a simple scalar, it is assumed to be a |
314 | filename. This file will be opened for writing and the uncompressed | |
315 | data will be written to it. | |
642e522c RGS |
316 | |
317 | =item A filehandle | |
318 | ||
1a6a8453 PM |
319 | If the C<$output> parameter is a filehandle, the uncompressed data |
320 | will be written to it. | |
642e522c RGS |
321 | The string '-' can be used as an alias for standard output. |
322 | ||
323 | ||
324 | =item A scalar reference | |
325 | ||
1a6a8453 PM |
326 | If C<$output> is a scalar reference, the uncompressed data will be |
327 | stored in C<$$output>. | |
642e522c | 328 | |
642e522c RGS |
329 | |
330 | ||
331 | =item An Array Reference | |
332 | ||
1a6a8453 PM |
333 | If C<$output> is an array reference, the uncompressed data will be |
334 | pushed onto the array. | |
642e522c RGS |
335 | |
336 | =item An Output FileGlob | |
337 | ||
338 | If C<$output> is a string that is delimited by the characters "<" and ">" | |
339 | C<anyinflate> will assume that it is an I<output fileglob string>. The | |
340 | output is the list of files that match the fileglob. | |
341 | ||
342 | When C<$output> is an fileglob string, C<$input> must also be a fileglob | |
343 | string. Anything else is an error. | |
344 | ||
345 | =back | |
346 | ||
347 | If the C<$output> parameter is any other type, C<undef> will be returned. | |
348 | ||
642e522c | 349 | |
642e522c RGS |
350 | |
351 | =head2 Notes | |
352 | ||
c70c1701 PM |
353 | |
354 | When C<$input> maps to multiple compressed files/buffers and C<$output> is | |
355 | a single file/buffer, after uncompression C<$output> will contain a | |
356 | concatenation of all the uncompressed data from each of the input | |
357 | files/buffers. | |
358 | ||
359 | ||
642e522c RGS |
360 | |
361 | ||
362 | ||
363 | =head2 Optional Parameters | |
364 | ||
365 | Unless specified below, the optional parameters for C<anyinflate>, | |
366 | C<OPTS>, are the same as those used with the OO interface defined in the | |
367 | L</"Constructor Options"> section below. | |
368 | ||
369 | =over 5 | |
370 | ||
e7d45986 | 371 | =item C<< AutoClose => 0|1 >> |
642e522c | 372 | |
1a6a8453 PM |
373 | This option applies to any input or output data streams to |
374 | C<anyinflate> that are filehandles. | |
642e522c RGS |
375 | |
376 | If C<AutoClose> is specified, and the value is true, it will result in all | |
377 | input and/or output filehandles being closed once C<anyinflate> has | |
378 | completed. | |
379 | ||
380 | This parameter defaults to 0. | |
381 | ||
382 | ||
e7d45986 | 383 | =item C<< BinModeOut => 0|1 >> |
1a6a8453 PM |
384 | |
385 | When writing to a file or filehandle, set C<binmode> before writing to the | |
386 | file. | |
387 | ||
388 | Defaults to 0. | |
389 | ||
390 | ||
391 | ||
392 | ||
393 | ||
e7d45986 | 394 | =item C<< Append => 0|1 >> |
642e522c RGS |
395 | |
396 | TODO | |
397 | ||
e7d45986 | 398 | =item C<< MultiStream => 0|1 >> |
1a6a8453 | 399 | |
e7d45986 PM |
400 | If the input file/buffer contains multiple compressed data streams, this |
401 | option will uncompress the whole lot as a single data stream. | |
1a6a8453 | 402 | |
e7d45986 | 403 | Defaults to 0. |
1a6a8453 | 404 | |
642e522c RGS |
405 | |
406 | ||
407 | =back | |
408 | ||
409 | ||
410 | ||
411 | ||
412 | =head2 Examples | |
413 | ||
414 | To read the contents of the file C<file1.txt.Compressed> and write the | |
415 | compressed data to the file C<file1.txt>. | |
416 | ||
417 | use strict ; | |
418 | use warnings ; | |
419 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
420 | ||
421 | my $input = "file1.txt.Compressed"; | |
422 | my $output = "file1.txt"; | |
423 | anyinflate $input => $output | |
424 | or die "anyinflate failed: $AnyInflateError\n"; | |
425 | ||
426 | ||
427 | To read from an existing Perl filehandle, C<$input>, and write the | |
428 | uncompressed data to a buffer, C<$buffer>. | |
429 | ||
430 | use strict ; | |
431 | use warnings ; | |
432 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
433 | use IO::File ; | |
434 | ||
435 | my $input = new IO::File "<file1.txt.Compressed" | |
436 | or die "Cannot open 'file1.txt.Compressed': $!\n" ; | |
437 | my $buffer ; | |
438 | anyinflate $input => \$buffer | |
439 | or die "anyinflate failed: $AnyInflateError\n"; | |
440 | ||
441 | To uncompress all files in the directory "/my/home" that match "*.txt.Compressed" and store the compressed data in the same directory | |
442 | ||
443 | use strict ; | |
444 | use warnings ; | |
445 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
446 | ||
447 | anyinflate '</my/home/*.txt.Compressed>' => '</my/home/#1.txt>' | |
448 | or die "anyinflate failed: $AnyInflateError\n"; | |
449 | ||
450 | and if you want to compress each file one at a time, this will do the trick | |
451 | ||
452 | use strict ; | |
453 | use warnings ; | |
454 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
455 | ||
456 | for my $input ( glob "/my/home/*.txt.Compressed" ) | |
457 | { | |
458 | my $output = $input; | |
459 | $output =~ s/.Compressed// ; | |
460 | anyinflate $input => $output | |
461 | or die "Error compressing '$input': $AnyInflateError\n"; | |
462 | } | |
463 | ||
464 | =head1 OO Interface | |
465 | ||
466 | =head2 Constructor | |
467 | ||
468 | The format of the constructor for IO::Uncompress::AnyInflate is shown below | |
469 | ||
470 | ||
471 | my $z = new IO::Uncompress::AnyInflate $input [OPTS] | |
472 | or die "IO::Uncompress::AnyInflate failed: $AnyInflateError\n"; | |
473 | ||
474 | Returns an C<IO::Uncompress::AnyInflate> object on success and undef on failure. | |
475 | The variable C<$AnyInflateError> will contain an error message on failure. | |
476 | ||
1a6a8453 PM |
477 | If you are running Perl 5.005 or better the object, C<$z>, returned from |
478 | IO::Uncompress::AnyInflate can be used exactly like an L<IO::File|IO::File> filehandle. | |
479 | This means that all normal input file operations can be carried out with | |
480 | C<$z>. For example, to read a line from a compressed file/buffer you can | |
481 | use either of these forms | |
642e522c RGS |
482 | |
483 | $line = $z->getline(); | |
484 | $line = <$z>; | |
485 | ||
486 | The mandatory parameter C<$input> is used to determine the source of the | |
487 | compressed data. This parameter can take one of three forms. | |
488 | ||
489 | =over 5 | |
490 | ||
491 | =item A filename | |
492 | ||
493 | If the C<$input> parameter is a scalar, it is assumed to be a filename. This | |
494 | file will be opened for reading and the compressed data will be read from it. | |
495 | ||
496 | =item A filehandle | |
497 | ||
498 | If the C<$input> parameter is a filehandle, the compressed data will be | |
499 | read from it. | |
500 | The string '-' can be used as an alias for standard input. | |
501 | ||
502 | ||
503 | =item A scalar reference | |
504 | ||
505 | If C<$input> is a scalar reference, the compressed data will be read from | |
506 | C<$$output>. | |
507 | ||
508 | =back | |
509 | ||
510 | =head2 Constructor Options | |
511 | ||
512 | ||
513 | The option names defined below are case insensitive and can be optionally | |
514 | prefixed by a '-'. So all of the following are valid | |
515 | ||
516 | -AutoClose | |
517 | -autoclose | |
518 | AUTOCLOSE | |
519 | autoclose | |
520 | ||
521 | OPTS is a combination of the following options: | |
522 | ||
523 | =over 5 | |
524 | ||
e7d45986 | 525 | =item C<< AutoClose => 0|1 >> |
642e522c RGS |
526 | |
527 | This option is only valid when the C<$input> parameter is a filehandle. If | |
528 | specified, and the value is true, it will result in the file being closed once | |
529 | either the C<close> method is called or the IO::Uncompress::AnyInflate object is | |
530 | destroyed. | |
531 | ||
532 | This parameter defaults to 0. | |
533 | ||
e7d45986 | 534 | =item C<< MultiStream => 0|1 >> |
642e522c RGS |
535 | |
536 | ||
537 | ||
538 | Allows multiple concatenated compressed streams to be treated as a single | |
539 | compressed stream. Decompression will stop once either the end of the | |
540 | file/buffer is reached, an error is encountered (premature eof, corrupt | |
541 | compressed data) or the end of a stream is not immediately followed by the | |
542 | start of another stream. | |
543 | ||
544 | This parameter defaults to 0. | |
545 | ||
546 | ||
e7d45986 | 547 | =item C<< Prime => $string >> |
642e522c RGS |
548 | |
549 | This option will uncompress the contents of C<$string> before processing the | |
550 | input file/buffer. | |
551 | ||
552 | This option can be useful when the compressed data is embedded in another | |
553 | file/data structure and it is not possible to work out where the compressed | |
1a6a8453 PM |
554 | data begins without having to read the first few bytes. If this is the |
555 | case, the uncompression can be I<primed> with these bytes using this | |
556 | option. | |
642e522c | 557 | |
e7d45986 | 558 | =item C<< Transparent => 0|1 >> |
642e522c RGS |
559 | |
560 | If this option is set and the input file or buffer is not compressed data, | |
561 | the module will allow reading of it anyway. | |
562 | ||
563 | This option defaults to 1. | |
564 | ||
e7d45986 | 565 | =item C<< BlockSize => $num >> |
642e522c | 566 | |
1a6a8453 PM |
567 | When reading the compressed input data, IO::Uncompress::AnyInflate will read it in |
568 | blocks of C<$num> bytes. | |
642e522c RGS |
569 | |
570 | This option defaults to 4096. | |
571 | ||
e7d45986 | 572 | =item C<< InputLength => $size >> |
642e522c | 573 | |
1a6a8453 PM |
574 | When present this option will limit the number of compressed bytes read |
575 | from the input file/buffer to C<$size>. This option can be used in the | |
576 | situation where there is useful data directly after the compressed data | |
577 | stream and you know beforehand the exact length of the compressed data | |
578 | stream. | |
642e522c | 579 | |
1a6a8453 PM |
580 | This option is mostly used when reading from a filehandle, in which case |
581 | the file pointer will be left pointing to the first byte directly after the | |
642e522c RGS |
582 | compressed data stream. |
583 | ||
584 | ||
585 | ||
586 | This option defaults to off. | |
587 | ||
e7d45986 | 588 | =item C<< Append => 0|1 >> |
642e522c RGS |
589 | |
590 | This option controls what the C<read> method does with uncompressed data. | |
591 | ||
1a6a8453 PM |
592 | If set to 1, all uncompressed data will be appended to the output parameter |
593 | of the C<read> method. | |
642e522c | 594 | |
1a6a8453 PM |
595 | If set to 0, the contents of the output parameter of the C<read> method |
596 | will be overwritten by the uncompressed data. | |
642e522c RGS |
597 | |
598 | Defaults to 0. | |
599 | ||
e7d45986 | 600 | =item C<< Strict => 0|1 >> |
642e522c RGS |
601 | |
602 | ||
603 | ||
604 | This option controls whether the extra checks defined below are used when | |
1a6a8453 PM |
605 | carrying out the decompression. When Strict is on, the extra tests are |
606 | carried out, when Strict is off they are not. | |
642e522c RGS |
607 | |
608 | The default for this option is off. | |
609 | ||
610 | ||
a02d0f6f | 611 | If the input is an RFC 1950 data stream, the following will be checked: |
642e522c RGS |
612 | |
613 | ||
614 | ||
615 | ||
616 | =over 5 | |
617 | ||
618 | =item 1 | |
619 | ||
620 | The ADLER32 checksum field must be present. | |
621 | ||
622 | =item 2 | |
623 | ||
624 | The value of the ADLER32 field read must match the adler32 value of the | |
625 | uncompressed data actually contained in the file. | |
626 | ||
627 | =back | |
628 | ||
629 | ||
630 | ||
a02d0f6f | 631 | If the input is a gzip (RFC 1952) data stream, the following will be checked: |
642e522c RGS |
632 | |
633 | ||
634 | ||
635 | ||
636 | =over 5 | |
637 | ||
638 | =item 1 | |
639 | ||
640 | If the FHCRC bit is set in the gzip FLG header byte, the CRC16 bytes in the | |
641 | header must match the crc16 value of the gzip header actually read. | |
642 | ||
643 | =item 2 | |
644 | ||
645 | If the gzip header contains a name field (FNAME) it consists solely of ISO | |
646 | 8859-1 characters. | |
647 | ||
648 | =item 3 | |
649 | ||
1a6a8453 PM |
650 | If the gzip header contains a comment field (FCOMMENT) it consists solely |
651 | of ISO 8859-1 characters plus line-feed. | |
642e522c RGS |
652 | |
653 | =item 4 | |
654 | ||
655 | If the gzip FEXTRA header field is present it must conform to the sub-field | |
a02d0f6f | 656 | structure as defined in RFC 1952. |
642e522c RGS |
657 | |
658 | =item 5 | |
659 | ||
660 | The CRC32 and ISIZE trailer fields must be present. | |
661 | ||
662 | =item 6 | |
663 | ||
664 | The value of the CRC32 field read must match the crc32 value of the | |
665 | uncompressed data actually contained in the gzip file. | |
666 | ||
667 | =item 7 | |
668 | ||
1a6a8453 PM |
669 | The value of the ISIZE fields read must match the length of the |
670 | uncompressed data actually read from the file. | |
642e522c RGS |
671 | |
672 | =back | |
673 | ||
674 | ||
675 | ||
676 | ||
677 | ||
678 | ||
e7d45986 | 679 | =item C<< ParseExtra => 0|1 >> |
642e522c RGS |
680 | |
681 | If the gzip FEXTRA header field is present and this option is set, it will | |
682 | force the module to check that it conforms to the sub-field structure as | |
a02d0f6f | 683 | defined in RFC 1952. |
642e522c RGS |
684 | |
685 | If the C<Strict> is on it will automatically enable this option. | |
686 | ||
687 | Defaults to 0. | |
688 | ||
689 | ||
690 | ||
a02d0f6f RGS |
691 | |
692 | ||
642e522c RGS |
693 | =back |
694 | ||
695 | =head2 Examples | |
696 | ||
697 | TODO | |
698 | ||
699 | =head1 Methods | |
700 | ||
701 | =head2 read | |
702 | ||
703 | Usage is | |
704 | ||
705 | $status = $z->read($buffer) | |
706 | ||
707 | Reads a block of compressed data (the size the the compressed block is | |
708 | determined by the C<Buffer> option in the constructor), uncompresses it and | |
1a6a8453 PM |
709 | writes any uncompressed data into C<$buffer>. If the C<Append> parameter is |
710 | set in the constructor, the uncompressed data will be appended to the | |
711 | C<$buffer> parameter. Otherwise C<$buffer> will be overwritten. | |
642e522c | 712 | |
1a6a8453 PM |
713 | Returns the number of uncompressed bytes written to C<$buffer>, zero if eof |
714 | or a negative number on error. | |
642e522c RGS |
715 | |
716 | =head2 read | |
717 | ||
718 | Usage is | |
719 | ||
720 | $status = $z->read($buffer, $length) | |
721 | $status = $z->read($buffer, $length, $offset) | |
722 | ||
723 | $status = read($z, $buffer, $length) | |
724 | $status = read($z, $buffer, $length, $offset) | |
725 | ||
726 | Attempt to read C<$length> bytes of uncompressed data into C<$buffer>. | |
727 | ||
1a6a8453 PM |
728 | The main difference between this form of the C<read> method and the |
729 | previous one, is that this one will attempt to return I<exactly> C<$length> | |
730 | bytes. The only circumstances that this function will not is if end-of-file | |
731 | or an IO error is encountered. | |
642e522c | 732 | |
1a6a8453 PM |
733 | Returns the number of uncompressed bytes written to C<$buffer>, zero if eof |
734 | or a negative number on error. | |
642e522c RGS |
735 | |
736 | ||
737 | =head2 getline | |
738 | ||
739 | Usage is | |
740 | ||
741 | $line = $z->getline() | |
742 | $line = <$z> | |
743 | ||
744 | Reads a single line. | |
745 | ||
746 | This method fully supports the use of of the variable C<$/> | |
747 | (or C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to | |
748 | determine what constitutes an end of line. Both paragraph mode and file | |
749 | slurp mode are supported. | |
750 | ||
751 | ||
752 | =head2 getc | |
753 | ||
754 | Usage is | |
755 | ||
756 | $char = $z->getc() | |
757 | ||
758 | Read a single character. | |
759 | ||
760 | =head2 ungetc | |
761 | ||
762 | Usage is | |
763 | ||
764 | $char = $z->ungetc($string) | |
765 | ||
766 | ||
a02d0f6f | 767 | |
642e522c RGS |
768 | =head2 inflateSync |
769 | ||
770 | Usage is | |
771 | ||
772 | $status = $z->inflateSync() | |
773 | ||
774 | TODO | |
775 | ||
a02d0f6f | 776 | |
642e522c RGS |
777 | =head2 getHeaderInfo |
778 | ||
779 | Usage is | |
780 | ||
1a6a8453 PM |
781 | $hdr = $z->getHeaderInfo(); |
782 | @hdrs = $z->getHeaderInfo(); | |
642e522c | 783 | |
1a6a8453 PM |
784 | This method returns either a hash reference (in scalar context) or a list |
785 | or hash references (in array context) that contains information about each | |
786 | of the header fields in the compressed data stream(s). | |
642e522c RGS |
787 | |
788 | ||
789 | ||
790 | ||
791 | =head2 tell | |
792 | ||
793 | Usage is | |
794 | ||
795 | $z->tell() | |
796 | tell $z | |
797 | ||
798 | Returns the uncompressed file offset. | |
799 | ||
800 | =head2 eof | |
801 | ||
802 | Usage is | |
803 | ||
804 | $z->eof(); | |
805 | eof($z); | |
806 | ||
807 | ||
808 | ||
809 | Returns true if the end of the compressed input stream has been reached. | |
810 | ||
811 | ||
812 | ||
813 | =head2 seek | |
814 | ||
815 | $z->seek($position, $whence); | |
816 | seek($z, $position, $whence); | |
817 | ||
818 | ||
819 | ||
820 | ||
821 | Provides a sub-set of the C<seek> functionality, with the restriction | |
822 | that it is only legal to seek forward in the input file/buffer. | |
823 | It is a fatal error to attempt to seek backward. | |
824 | ||
825 | ||
826 | ||
827 | The C<$whence> parameter takes one the usual values, namely SEEK_SET, | |
828 | SEEK_CUR or SEEK_END. | |
829 | ||
830 | Returns 1 on success, 0 on failure. | |
831 | ||
832 | =head2 binmode | |
833 | ||
834 | Usage is | |
835 | ||
836 | $z->binmode | |
837 | binmode $z ; | |
838 | ||
839 | This is a noop provided for completeness. | |
840 | ||
a02d0f6f RGS |
841 | =head2 opened |
842 | ||
843 | $z->opened() | |
844 | ||
845 | Returns true if the object currently refers to a opened file/buffer. | |
846 | ||
847 | =head2 autoflush | |
848 | ||
849 | my $prev = $z->autoflush() | |
850 | my $prev = $z->autoflush(EXPR) | |
851 | ||
852 | If the C<$z> object is associated with a file or a filehandle, this method | |
853 | returns the current autoflush setting for the underlying filehandle. If | |
854 | C<EXPR> is present, and is non-zero, it will enable flushing after every | |
855 | write/print operation. | |
856 | ||
857 | If C<$z> is associated with a buffer, this method has no effect and always | |
858 | returns C<undef>. | |
859 | ||
860 | B<Note> that the special variable C<$|> B<cannot> be used to set or | |
861 | retrieve the autoflush setting. | |
862 | ||
863 | =head2 input_line_number | |
864 | ||
865 | $z->input_line_number() | |
866 | $z->input_line_number(EXPR) | |
867 | ||
868 | ||
869 | ||
870 | Returns the current uncompressed line number. If C<EXPR> is present it has | |
871 | the effect of setting the line number. Note that setting the line number | |
872 | does not change the current position within the file/buffer being read. | |
873 | ||
874 | The contents of C<$/> are used to to determine what constitutes a line | |
875 | terminator. | |
876 | ||
877 | ||
878 | ||
642e522c RGS |
879 | =head2 fileno |
880 | ||
881 | $z->fileno() | |
882 | fileno($z) | |
883 | ||
a02d0f6f RGS |
884 | If the C<$z> object is associated with a file or a filehandle, this method |
885 | will return the underlying file descriptor. | |
642e522c RGS |
886 | |
887 | If the C<$z> object is is associated with a buffer, this method will | |
888 | return undef. | |
889 | ||
890 | =head2 close | |
891 | ||
892 | $z->close() ; | |
893 | close $z ; | |
894 | ||
895 | ||
896 | ||
897 | Closes the output file/buffer. | |
898 | ||
899 | ||
900 | ||
901 | For most versions of Perl this method will be automatically invoked if | |
902 | the IO::Uncompress::AnyInflate object is destroyed (either explicitly or by the | |
903 | variable with the reference to the object going out of scope). The | |
904 | exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In | |
905 | these cases, the C<close> method will be called automatically, but | |
906 | not until global destruction of all live objects when the program is | |
907 | terminating. | |
908 | ||
909 | Therefore, if you want your scripts to be able to run on all versions | |
910 | of Perl, you should call C<close> explicitly and not rely on automatic | |
911 | closing. | |
912 | ||
913 | Returns true on success, otherwise 0. | |
914 | ||
915 | If the C<AutoClose> option has been enabled when the IO::Uncompress::AnyInflate | |
916 | object was created, and the object is associated with a file, the | |
917 | underlying file will also be closed. | |
918 | ||
919 | ||
920 | ||
921 | ||
e7d45986 PM |
922 | =head2 nextStream |
923 | ||
924 | Usage is | |
925 | ||
926 | my $status = $z->nextStream(); | |
927 | ||
928 | Skips to the next compressed data stream in the input file/buffer. If a new | |
929 | compressed data stream is found, the eof marker will be cleared, C<$.> will | |
930 | be reset to 0. | |
931 | ||
932 | Returns 1 if a new stream was found, 0 if none was found, and -1 if an | |
933 | error was encountered. | |
934 | ||
935 | =head2 trailingData | |
936 | ||
937 | Usage is | |
938 | ||
939 | my $data = $z->trailingData(); | |
940 | ||
941 | Returns any data that | |
942 | ||
642e522c RGS |
943 | =head1 Importing |
944 | ||
945 | No symbolic constants are required by this IO::Uncompress::AnyInflate at present. | |
946 | ||
947 | =over 5 | |
948 | ||
949 | =item :all | |
950 | ||
951 | Imports C<anyinflate> and C<$AnyInflateError>. | |
952 | Same as doing this | |
953 | ||
954 | use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ; | |
955 | ||
956 | =back | |
957 | ||
958 | =head1 EXAMPLES | |
959 | ||
960 | ||
961 | ||
962 | ||
963 | =head1 SEE ALSO | |
964 | ||
a02d0f6f | 965 | L<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Uncompress::AnyUncompress> |
642e522c RGS |
966 | |
967 | L<Compress::Zlib::FAQ|Compress::Zlib::FAQ> | |
968 | ||
a02d0f6f RGS |
969 | L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>, |
970 | L<Archive::Tar|Archive::Tar>, | |
642e522c RGS |
971 | L<IO::Zlib|IO::Zlib> |
972 | ||
a02d0f6f | 973 | |
642e522c RGS |
974 | For RFC 1950, 1951 and 1952 see |
975 | F<http://www.faqs.org/rfcs/rfc1950.html>, | |
976 | F<http://www.faqs.org/rfcs/rfc1951.html> and | |
977 | F<http://www.faqs.org/rfcs/rfc1952.html> | |
978 | ||
a02d0f6f RGS |
979 | The I<zlib> compression library was written by Jean-loup Gailly |
980 | F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>. | |
981 | ||
982 | The primary site for the I<zlib> compression library is | |
983 | F<http://www.zlib.org>. | |
984 | ||
985 | The primary site for gzip is F<http://www.gzip.org>. | |
986 | ||
987 | ||
988 | ||
989 | ||
642e522c RGS |
990 | =head1 AUTHOR |
991 | ||
cb7abd7f | 992 | This module was written by Paul Marquess, F<pmqs@cpan.org>. |
642e522c | 993 | |
642e522c | 994 | |
642e522c RGS |
995 | |
996 | =head1 MODIFICATION HISTORY | |
997 | ||
998 | See the Changes file. | |
999 | ||
1000 | =head1 COPYRIGHT AND LICENSE | |
642e522c | 1001 | |
1a6a8453 | 1002 | Copyright (c) 2005-2006 Paul Marquess. All rights reserved. |
a02d0f6f | 1003 | |
642e522c RGS |
1004 | This program is free software; you can redistribute it and/or |
1005 | modify it under the same terms as Perl itself. | |
1006 |