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