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