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