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