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