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