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