File Coverage

blib/lib/IO/Uncompress/RawInflate.pm
Criterion Covered Total %
statement 112 117 95.7
branch 34 48 70.8
condition 12 24 50.0
subroutine 21 21 100.0
pod 3 12 25.0
total 182 222 81.9


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