1package IO::Uncompress::Inflate ;
2# for RFC1950
3
4use strict ;
5use warnings;
6use bytes;
7
8use IO::Compress::Base::Common  2.084 qw(:Status );
9use IO::Compress::Zlib::Constants 2.084 ;
10
11use IO::Uncompress::RawInflate  2.084 ;
12
13require Exporter ;
14our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $InflateError);
15
16$VERSION = '2.084';
17$InflateError = '';
18
19@ISA    = qw(IO::Uncompress::RawInflate Exporter);
20@EXPORT_OK = qw( $InflateError inflate ) ;
21%EXPORT_TAGS = %IO::Uncompress::RawInflate::DEFLATE_CONSTANTS ;
22push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
23Exporter::export_ok_tags('all');
24
25
26sub new
27{
28    my $class = shift ;
29    my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$InflateError);
30
31    $obj->_create(undef, 0, @_);
32}
33
34sub inflate
35{
36    my $obj = IO::Compress::Base::Common::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->setValue('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
69    #return $self->HeaderError("CRC mismatch.")
70    return undef
71        if ! $self->isZlibMagic($magic) ;
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
95    return STATUS_OK;
96}
97
98
99
100sub isZlibMagic
101{
102    my $self = shift;
103    my $buffer = shift ;
104
105    return 0
106        if length $buffer < ZLIB_HEADER_SIZE ;
107
108    my $hdr = unpack("n", $buffer) ;
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;
127}
128
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
1951 ;
196
197__END__
198
199
200=head1 NAME
201
202IO::Uncompress::Inflate - Read RFC 1950 files/buffers
203
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()
220    $char = $z->opened()
221
222    $status = $z->inflateSync()
223
224    $data = $z->trailingData()
225    $status = $z->nextStream()
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
249=head1 DESCRIPTION
250
251This module provides a Perl interface that allows the reading of
252files/buffers that conform to RFC 1950.
253
254For writing RFC 1950 files/buffers, see the companion module IO::Compress::Deflate.
255
256=head1 Functional Interface
257
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.
262
263    use IO::Uncompress::Inflate qw(inflate $InflateError) ;
264
265    inflate $input_filename_or_reference => $output_filename_or_reference [,OPTS]
266        or die "inflate failed: $InflateError\n";
267
268The functional interface needs Perl5.005 or better.
269
270=head2 inflate $input_filename_or_reference => $output_filename_or_reference [, OPTS]
271
272C<inflate> expects at least two parameters,
273C<$input_filename_or_reference> and C<$output_filename_or_reference>.
274
275=head3 The C<$input_filename_or_reference> parameter
276
277The parameter, C<$input_filename_or_reference>, is used to define the
278source of the compressed data.
279
280It can take one of the following forms:
281
282=over 5
283
284=item A filename
285
286If the <$input_filename_or_reference> parameter is a simple scalar, it is
287assumed to be a filename. This file will be opened for reading and the
288input data will be read from it.
289
290=item A filehandle
291
292If the C<$input_filename_or_reference> parameter is a filehandle, the input
293data will be read from it.  The string '-' can be used as an alias for
294standard input.
295
296=item A scalar reference
297
298If C<$input_filename_or_reference> is a scalar reference, the input data
299will be read from C<$$input_filename_or_reference>.
300
301=item An array reference
302
303If C<$input_filename_or_reference> is an array reference, each element in
304the array must be a filename.
305
306The input data will be read from each file in turn.
307
308The complete array will be walked to ensure that it only
309contains valid filenames before any data is uncompressed.
310
311=item An Input FileGlob string
312
313If C<$input_filename_or_reference> is a string that is delimited by the
314characters "<" and ">" C<inflate> will assume that it is an
315I<input fileglob string>. The input is the list of files that match the
316fileglob.
317
318See L<File::GlobMapper|File::GlobMapper> for more details.
319
320=back
321
322If the C<$input_filename_or_reference> parameter is any other type,
323C<undef> will be returned.
324
325=head3 The C<$output_filename_or_reference> parameter
326
327The parameter C<$output_filename_or_reference> is used to control the
328destination of the uncompressed data. This parameter can take one of
329these forms.
330
331=over 5
332
333=item A filename
334
335If the C<$output_filename_or_reference> parameter is a simple scalar, it is
336assumed to be a filename.  This file will be opened for writing and the
337uncompressed data will be written to it.
338
339=item A filehandle
340
341If the C<$output_filename_or_reference> parameter is a filehandle, the
342uncompressed data will be written to it.  The string '-' can be used as
343an alias for standard output.
344
345=item A scalar reference
346
347If C<$output_filename_or_reference> is a scalar reference, the
348uncompressed data will be stored in C<$$output_filename_or_reference>.
349
350=item An Array Reference
351
352If C<$output_filename_or_reference> is an array reference,
353the uncompressed data will be pushed onto the array.
354
355=item An Output FileGlob
356
357If C<$output_filename_or_reference> is a string that is delimited by the
358characters "<" and ">" C<inflate> will assume that it is an
359I<output fileglob string>. The output is the list of files that match the
360fileglob.
361
362When C<$output_filename_or_reference> is an fileglob string,
363C<$input_filename_or_reference> must also be a fileglob string. Anything
364else is an error.
365
366See L<File::GlobMapper|File::GlobMapper> for more details.
367
368=back
369
370If the C<$output_filename_or_reference> parameter is any other type,
371C<undef> will be returned.
372
373=head2 Notes
374
375When C<$input_filename_or_reference> maps to multiple compressed
376files/buffers and C<$output_filename_or_reference> is
377a single file/buffer, after uncompression C<$output_filename_or_reference> will contain a
378concatenation of all the uncompressed data from each of the input
379files/buffers.
380
381=head2 Optional Parameters
382
383Unless specified below, the optional parameters for C<inflate>,
384C<OPTS>, are the same as those used with the OO interface defined in the
385L</"Constructor Options"> section below.
386
387=over 5
388
389=item C<< AutoClose => 0|1 >>
390
391This option applies to any input or output data streams to
392C<inflate> that are filehandles.
393
394If C<AutoClose> is specified, and the value is true, it will result in all
395input and/or output filehandles being closed once C<inflate> has
396completed.
397
398This parameter defaults to 0.
399
400=item C<< BinModeOut => 0|1 >>
401
402This option is now a no-op. All files will be written  in binmode.
403
404=item C<< Append => 0|1 >>
405
406The behaviour of this option is dependent on the type of output data
407stream.
408
409=over 5
410
411=item * A Buffer
412
413If C<Append> is enabled, all uncompressed data will be append to the end of
414the output buffer. Otherwise the output buffer will be cleared before any
415uncompressed data is written to it.
416
417=item * A Filename
418
419If C<Append> is enabled, the file will be opened in append mode. Otherwise
420the contents of the file, if any, will be truncated before any uncompressed
421data is written to it.
422
423=item * A Filehandle
424
425If C<Append> is enabled, the filehandle will be positioned to the end of
426the file via a call to C<seek> before any uncompressed data is
427written to it.  Otherwise the file pointer will not be moved.
428
429=back
430
431When C<Append> is specified, and set to true, it will I<append> all uncompressed
432data to the output data stream.
433
434So when the output is a filehandle it will carry out a seek to the eof
435before writing any uncompressed data. If the output is a filename, it will be opened for
436appending. If the output is a buffer, all uncompressed data will be
437appended to the existing buffer.
438
439Conversely when C<Append> is not specified, or it is present and is set to
440false, it will operate as follows.
441
442When the output is a filename, it will truncate the contents of the file
443before writing any uncompressed data. If the output is a filehandle
444its position will not be changed. If the output is a buffer, it will be
445wiped before any uncompressed data is output.
446
447Defaults to 0.
448
449=item C<< MultiStream => 0|1 >>
450
451If the input file/buffer contains multiple compressed data streams, this
452option will uncompress the whole lot as a single data stream.
453
454Defaults to 0.
455
456=item C<< TrailingData => $scalar >>
457
458Returns the data, if any, that is present immediately after the compressed
459data stream once uncompression is complete.
460
461This option can be used when there is useful information immediately
462following the compressed data stream, and you don't know the length of the
463compressed data stream.
464
465If the input is a buffer, C<trailingData> will return everything from the
466end of the compressed data stream to the end of the buffer.
467
468If the input is a filehandle, C<trailingData> will return the data that is
469left in the filehandle input buffer once the end of the compressed data
470stream has been reached. You can then use the filehandle to read the rest
471of the input file.
472
473Don't bother using C<trailingData> if the input is a filename.
474
475If you know the length of the compressed data stream before you start
476uncompressing, you can avoid having to use C<trailingData> by setting the
477C<InputLength> option.
478
479=back
480
481=head2 Examples
482
483To read the contents of the file C<file1.txt.1950> and write the
484uncompressed data to the file C<file1.txt>.
485
486    use strict ;
487    use warnings ;
488    use IO::Uncompress::Inflate qw(inflate $InflateError) ;
489
490    my $input = "file1.txt.1950";
491    my $output = "file1.txt";
492    inflate $input => $output
493        or die "inflate failed: $InflateError\n";
494
495To read from an existing Perl filehandle, C<$input>, and write the
496uncompressed data to a buffer, C<$buffer>.
497
498    use strict ;
499    use warnings ;
500    use IO::Uncompress::Inflate qw(inflate $InflateError) ;
501    use IO::File ;
502
503    my $input = new IO::File "<file1.txt.1950"
504        or die "Cannot open 'file1.txt.1950': $!\n" ;
505    my $buffer ;
506    inflate $input => \$buffer
507        or die "inflate failed: $InflateError\n";
508
509To uncompress all files in the directory "/my/home" that match "*.txt.1950" and store the compressed data in the same directory
510
511    use strict ;
512    use warnings ;
513    use IO::Uncompress::Inflate qw(inflate $InflateError) ;
514
515    inflate '</my/home/*.txt.1950>' => '</my/home/#1.txt>'
516        or die "inflate failed: $InflateError\n";
517
518and if you want to compress each file one at a time, this will do the trick
519
520    use strict ;
521    use warnings ;
522    use IO::Uncompress::Inflate qw(inflate $InflateError) ;
523
524    for my $input ( glob "/my/home/*.txt.1950" )
525    {
526        my $output = $input;
527        $output =~ s/.1950// ;
528        inflate $input => $output
529            or die "Error compressing '$input': $InflateError\n";
530    }
531
532=head1 OO Interface
533
534=head2 Constructor
535
536The format of the constructor for IO::Uncompress::Inflate is shown below
537
538    my $z = new IO::Uncompress::Inflate $input [OPTS]
539        or die "IO::Uncompress::Inflate failed: $InflateError\n";
540
541Returns an C<IO::Uncompress::Inflate> object on success and undef on failure.
542The variable C<$InflateError> will contain an error message on failure.
543
544If you are running Perl 5.005 or better the object, C<$z>, returned from
545IO::Uncompress::Inflate can be used exactly like an L<IO::File|IO::File> filehandle.
546This means that all normal input file operations can be carried out with
547C<$z>.  For example, to read a line from a compressed file/buffer you can
548use either of these forms
549
550    $line = $z->getline();
551    $line = <$z>;
552
553The mandatory parameter C<$input> is used to determine the source of the
554compressed data. This parameter can take one of three forms.
555
556=over 5
557
558=item A filename
559
560If the C<$input> parameter is a scalar, it is assumed to be a filename. This
561file will be opened for reading and the compressed data will be read from it.
562
563=item A filehandle
564
565If the C<$input> parameter is a filehandle, the compressed data will be
566read from it.
567The string '-' can be used as an alias for standard input.
568
569=item A scalar reference
570
571If C<$input> is a scalar reference, the compressed data will be read from
572C<$$input>.
573
574=back
575
576=head2 Constructor Options
577
578The option names defined below are case insensitive and can be optionally
579prefixed by a '-'.  So all of the following are valid
580
581    -AutoClose
582    -autoclose
583    AUTOCLOSE
584    autoclose
585
586OPTS is a combination of the following options:
587
588=over 5
589
590=item C<< AutoClose => 0|1 >>
591
592This option is only valid when the C<$input> parameter is a filehandle. If
593specified, and the value is true, it will result in the file being closed once
594either the C<close> method is called or the IO::Uncompress::Inflate object is
595destroyed.
596
597This parameter defaults to 0.
598
599=item C<< MultiStream => 0|1 >>
600
601Allows multiple concatenated compressed streams to be treated as a single
602compressed stream. Decompression will stop once either the end of the
603file/buffer is reached, an error is encountered (premature eof, corrupt
604compressed data) or the end of a stream is not immediately followed by the
605start of another stream.
606
607This parameter defaults to 0.
608
609=item C<< Prime => $string >>
610
611This option will uncompress the contents of C<$string> before processing the
612input file/buffer.
613
614This option can be useful when the compressed data is embedded in another
615file/data structure and it is not possible to work out where the compressed
616data begins without having to read the first few bytes. If this is the
617case, the uncompression can be I<primed> with these bytes using this
618option.
619
620=item C<< Transparent => 0|1 >>
621
622If this option is set and the input file/buffer is not compressed data,
623the module will allow reading of it anyway.
624
625In addition, if the input file/buffer does contain compressed data and
626there is non-compressed data immediately following it, setting this option
627will make this module treat the whole file/buffer as a single data stream.
628
629This option defaults to 1.
630
631=item C<< BlockSize => $num >>
632
633When reading the compressed input data, IO::Uncompress::Inflate will read it in
634blocks of C<$num> bytes.
635
636This option defaults to 4096.
637
638=item C<< InputLength => $size >>
639
640When present this option will limit the number of compressed bytes read
641from the input file/buffer to C<$size>. This option can be used in the
642situation where there is useful data directly after the compressed data
643stream and you know beforehand the exact length of the compressed data
644stream.
645
646This option is mostly used when reading from a filehandle, in which case
647the file pointer will be left pointing to the first byte directly after the
648compressed data stream.
649
650This option defaults to off.
651
652=item C<< Append => 0|1 >>
653
654This option controls what the C<read> method does with uncompressed data.
655
656If set to 1, all uncompressed data will be appended to the output parameter
657of the C<read> method.
658
659If set to 0, the contents of the output parameter of the C<read> method
660will be overwritten by the uncompressed data.
661
662Defaults to 0.
663
664=item C<< Strict => 0|1 >>
665
666This option controls whether the extra checks defined below are used when
667carrying out the decompression. When Strict is on, the extra tests are
668carried out, when Strict is off they are not.
669
670The default for this option is off.
671
672=over 5
673
674=item 1
675
676The ADLER32 checksum field must be present.
677
678=item 2
679
680The value of the ADLER32 field read must match the adler32 value of the
681uncompressed data actually contained in the file.
682
683=back
684
685=back
686
687=head2 Examples
688
689TODO
690
691=head1 Methods
692
693=head2 read
694
695Usage is
696
697    $status = $z->read($buffer)
698
699Reads a block of compressed data (the size of the compressed block is
700determined by the C<Buffer> option in the constructor), uncompresses it and
701writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
702set in the constructor, the uncompressed data will be appended to the
703C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
704
705Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
706or a negative number on error.
707
708=head2 read
709
710Usage is
711
712    $status = $z->read($buffer, $length)
713    $status = $z->read($buffer, $length, $offset)
714
715    $status = read($z, $buffer, $length)
716    $status = read($z, $buffer, $length, $offset)
717
718Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
719
720The main difference between this form of the C<read> method and the
721previous one, is that this one will attempt to return I<exactly> C<$length>
722bytes. The only circumstances that this function will not is if end-of-file
723or an IO error is encountered.
724
725Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
726or a negative number on error.
727
728=head2 getline
729
730Usage is
731
732    $line = $z->getline()
733    $line = <$z>
734
735Reads a single line.
736
737This method fully supports the use of the variable C<$/> (or
738C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
739determine what constitutes an end of line. Paragraph mode, record mode and
740file slurp mode are all supported.
741
742=head2 getc
743
744Usage is
745
746    $char = $z->getc()
747
748Read a single character.
749
750=head2 ungetc
751
752Usage is
753
754    $char = $z->ungetc($string)
755
756=head2 inflateSync
757
758Usage is
759
760    $status = $z->inflateSync()
761
762TODO
763
764=head2 getHeaderInfo
765
766Usage is
767
768    $hdr  = $z->getHeaderInfo();
769    @hdrs = $z->getHeaderInfo();
770
771This method returns either a hash reference (in scalar context) or a list
772or hash references (in array context) that contains information about each
773of the header fields in the compressed data stream(s).
774
775=head2 tell
776
777Usage is
778
779    $z->tell()
780    tell $z
781
782Returns the uncompressed file offset.
783
784=head2 eof
785
786Usage is
787
788    $z->eof();
789    eof($z);
790
791Returns true if the end of the compressed input stream has been reached.
792
793=head2 seek
794
795    $z->seek($position, $whence);
796    seek($z, $position, $whence);
797
798Provides a sub-set of the C<seek> functionality, with the restriction
799that it is only legal to seek forward in the input file/buffer.
800It is a fatal error to attempt to seek backward.
801
802Note that the implementation of C<seek> in this module does not provide
803true random access to a compressed file/buffer. It  works by uncompressing
804data from the current offset in the file/buffer until it reaches the
805uncompressed offset specified in the parameters to C<seek>. For very small
806files this may be acceptable behaviour. For large files it may cause an
807unacceptable delay.
808
809The C<$whence> parameter takes one the usual values, namely SEEK_SET,
810SEEK_CUR or SEEK_END.
811
812Returns 1 on success, 0 on failure.
813
814=head2 binmode
815
816Usage is
817
818    $z->binmode
819    binmode $z ;
820
821This is a noop provided for completeness.
822
823=head2 opened
824
825    $z->opened()
826
827Returns true if the object currently refers to a opened file/buffer.
828
829=head2 autoflush
830
831    my $prev = $z->autoflush()
832    my $prev = $z->autoflush(EXPR)
833
834If the C<$z> object is associated with a file or a filehandle, this method
835returns the current autoflush setting for the underlying filehandle. If
836C<EXPR> is present, and is non-zero, it will enable flushing after every
837write/print operation.
838
839If C<$z> is associated with a buffer, this method has no effect and always
840returns C<undef>.
841
842B<Note> that the special variable C<$|> B<cannot> be used to set or
843retrieve the autoflush setting.
844
845=head2 input_line_number
846
847    $z->input_line_number()
848    $z->input_line_number(EXPR)
849
850Returns the current uncompressed line number. If C<EXPR> is present it has
851the effect of setting the line number. Note that setting the line number
852does not change the current position within the file/buffer being read.
853
854The contents of C<$/> are used to determine what constitutes a line
855terminator.
856
857=head2 fileno
858
859    $z->fileno()
860    fileno($z)
861
862If the C<$z> object is associated with a file or a filehandle, C<fileno>
863will return the underlying file descriptor. Once the C<close> method is
864called C<fileno> will return C<undef>.
865
866If the C<$z> object is associated with a buffer, this method will return
867C<undef>.
868
869=head2 close
870
871    $z->close() ;
872    close $z ;
873
874Closes the output file/buffer.
875
876For most versions of Perl this method will be automatically invoked if
877the IO::Uncompress::Inflate object is destroyed (either explicitly or by the
878variable with the reference to the object going out of scope). The
879exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
880these cases, the C<close> method will be called automatically, but
881not until global destruction of all live objects when the program is
882terminating.
883
884Therefore, if you want your scripts to be able to run on all versions
885of Perl, you should call C<close> explicitly and not rely on automatic
886closing.
887
888Returns true on success, otherwise 0.
889
890If the C<AutoClose> option has been enabled when the IO::Uncompress::Inflate
891object was created, and the object is associated with a file, the
892underlying file will also be closed.
893
894=head2 nextStream
895
896Usage is
897
898    my $status = $z->nextStream();
899
900Skips to the next compressed data stream in the input file/buffer. If a new
901compressed data stream is found, the eof marker will be cleared and C<$.>
902will be reset to 0.
903
904Returns 1 if a new stream was found, 0 if none was found, and -1 if an
905error was encountered.
906
907=head2 trailingData
908
909Usage is
910
911    my $data = $z->trailingData();
912
913Returns the data, if any, that is present immediately after the compressed
914data stream once uncompression is complete. It only makes sense to call
915this method once the end of the compressed data stream has been
916encountered.
917
918This option can be used when there is useful information immediately
919following the compressed data stream, and you don't know the length of the
920compressed data stream.
921
922If the input is a buffer, C<trailingData> will return everything from the
923end of the compressed data stream to the end of the buffer.
924
925If the input is a filehandle, C<trailingData> will return the data that is
926left in the filehandle input buffer once the end of the compressed data
927stream has been reached. You can then use the filehandle to read the rest
928of the input file.
929
930Don't bother using C<trailingData> if the input is a filename.
931
932If you know the length of the compressed data stream before you start
933uncompressing, you can avoid having to use C<trailingData> by setting the
934C<InputLength> option in the constructor.
935
936=head1 Importing
937
938No symbolic constants are required by this IO::Uncompress::Inflate at present.
939
940=over 5
941
942=item :all
943
944Imports C<inflate> and C<$InflateError>.
945Same as doing this
946
947    use IO::Uncompress::Inflate qw(inflate $InflateError) ;
948
949=back
950
951=head1 EXAMPLES
952
953=head2 Working with Net::FTP
954
955See L<IO::Compress::FAQ|IO::Compress::FAQ/"Compressed files and Net::FTP">
956
957=head1 SEE ALSO
958
959L<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::Lzma>, L<IO::Uncompress::UnLzma>, L<IO::Compress::Xz>, L<IO::Uncompress::UnXz>, L<IO::Compress::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
960
961L<IO::Compress::FAQ|IO::Compress::FAQ>
962
963L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
964L<Archive::Tar|Archive::Tar>,
965L<IO::Zlib|IO::Zlib>
966
967For RFC 1950, 1951 and 1952 see
968L<http://www.faqs.org/rfcs/rfc1950.html>,
969L<http://www.faqs.org/rfcs/rfc1951.html> and
970L<http://www.faqs.org/rfcs/rfc1952.html>
971
972The I<zlib> compression library was written by Jean-loup Gailly
973C<gzip@prep.ai.mit.edu> and Mark Adler C<madler@alumni.caltech.edu>.
974
975The primary site for the I<zlib> compression library is
976L<http://www.zlib.org>.
977
978The primary site for gzip is L<http://www.gzip.org>.
979
980=head1 AUTHOR
981
982This module was written by Paul Marquess, C<pmqs@cpan.org>.
983
984=head1 MODIFICATION HISTORY
985
986See the Changes file.
987
988=head1 COPYRIGHT AND LICENSE
989
990Copyright (c) 2005-2019 Paul Marquess. All rights reserved.
991
992This program is free software; you can redistribute it and/or
993modify it under the same terms as Perl itself.
994
995