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