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