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