File Coverage

blib/lib/IO/Uncompress/Inflate.pm
Criterion Covered Total %
statement 68 70 97.1
branch 14 20 70.0
condition 3 3 100.0
subroutine 16 16 100.0
pod 2 9 22.2
total 103 118 87.2


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