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