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