File Coverage

blib/lib/IO/Uncompress/AnyInflate.pm
Criterion Covered Total %
statement 64 66 96.9
branch 6 8 75.0
condition n/a
subroutine 15 16 93.7
pod 2 6 33.3
total 87 96 90.6


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