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