53271aba01dc8564c828308caf2f5e1313f8bcc3
[p5sagit/p5-mst-13.2.git] / ext / Compress / IO / Zlib / lib / IO / Uncompress / RawInflate.pm
1 package IO::Uncompress::RawInflate ;
2 # for RFC1951
3
4 use strict ;
5 use warnings;
6 use bytes;
7
8 use Compress::Raw::Zlib ;
9 use IO::Compress::Base::Common qw(:Status createSelfTiedObject);
10
11 use IO::Uncompress::Base ;
12 use IO::Uncompress::Adapter::Inflate ;
13
14
15
16
17 require Exporter ;
18 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, %DEFLATE_CONSTANTS, $RawInflateError);
19
20 $VERSION = '2.000_14';
21 $RawInflateError = '';
22
23 @ISA    = qw( Exporter IO::Uncompress::Base );
24 @EXPORT_OK = qw( $RawInflateError rawinflate ) ;
25 %DEFLATE_CONSTANTS = ();
26 %EXPORT_TAGS = %IO::Uncompress::Base::EXPORT_TAGS ;
27 push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
28 Exporter::export_ok_tags('all');
29
30
31
32 sub new
33 {
34     my $class = shift ;
35     my $obj = createSelfTiedObject($class, \$RawInflateError);
36     $obj->_create(undef, 0, @_);
37 }
38
39 sub rawinflate
40 {
41     my $obj = createSelfTiedObject(undef, \$RawInflateError);
42     return $obj->_inf(@_);
43 }
44
45 sub getExtraParams
46 {
47     return ();
48 }
49
50 sub ckParams
51 {
52     my $self = shift ;
53     my $got = shift ;
54
55     return 1;
56 }
57
58 sub mkUncomp
59 {
60     my $self = shift ;
61     my $class = shift ;
62     my $got = shift ;
63
64     my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject(
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
86 sub ckMagic
87 {
88     my $self = shift;
89
90     return $self->_isRaw() ;
91 }
92
93 sub 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
107 sub chkTrailer
108 {
109     return STATUS_OK ;
110 }
111
112 sub _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 ;
128 }
129
130 sub _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
149     #my $buf_len = *$self->{Uncomp}->uncompressedBytes();
150     my $buf_len = length $buffer;
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
180 sub 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
269 sub 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
286 sub 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
313 sub 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
327 1; 
328
329 __END__
330
331
332 =head1 NAME
333
334
335
336 IO::Uncompress::RawInflate - Read RFC 1951 files/buffers
337
338
339
340 =head1 SYNOPSIS
341
342     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
343
344     my $status = rawinflate $input => $output [,OPTS]
345         or die "rawinflate failed: $RawInflateError\n";
346
347     my $z = new IO::Uncompress::RawInflate $input [OPTS] 
348         or die "rawinflate failed: $RawInflateError\n";
349
350     $status = $z->read($buffer)
351     $status = $z->read($buffer, $length)
352     $status = $z->read($buffer, $length, $offset)
353     $line = $z->getline()
354     $char = $z->getc()
355     $char = $z->ungetc()
356     $char = $z->opened()
357
358     $status = $z->inflateSync()
359
360     $data = $z->trailingData()
361     $status = $z->nextStream()
362     $data = $z->getHeaderInfo()
363     $z->tell()
364     $z->seek($position, $whence)
365     $z->binmode()
366     $z->fileno()
367     $z->eof()
368     $z->close()
369
370     $RawInflateError ;
371
372     # IO::File mode
373
374     <$z>
375     read($z, $buffer);
376     read($z, $buffer, $length);
377     read($z, $buffer, $length, $offset);
378     tell($z)
379     seek($z, $position, $whence)
380     binmode($z)
381     fileno($z)
382     eof($z)
383     close($z)
384
385
386 =head1 DESCRIPTION
387
388
389
390 B<WARNING -- This is a Beta release>. 
391
392 =over 5
393
394 =item * DO NOT use in production code.
395
396 =item * The documentation is incomplete in places.
397
398 =item * Parts of the interface defined here are tentative.
399
400 =item * Please report any problems you find.
401
402 =back
403
404
405
406
407
408 This module provides a Perl interface that allows the reading of
409 files/buffers that conform to RFC 1951.
410
411 For writing RFC 1951 files/buffers, see the companion module IO::Compress::RawDeflate.
412
413
414
415
416
417 =head1 Functional Interface
418
419 A top-level function, C<rawinflate>, is provided to carry out
420 "one-shot" uncompression between buffers and/or files. For finer
421 control over the uncompression process, see the L</"OO Interface">
422 section.
423
424     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
425
426     rawinflate $input => $output [,OPTS] 
427         or die "rawinflate failed: $RawInflateError\n";
428
429
430
431 The functional interface needs Perl5.005 or better.
432
433
434 =head2 rawinflate $input => $output [, OPTS]
435
436
437 C<rawinflate> expects at least two parameters, C<$input> and C<$output>.
438
439 =head3 The C<$input> parameter
440
441 The parameter, C<$input>, is used to define the source of
442 the compressed data. 
443
444 It can take one of the following forms:
445
446 =over 5
447
448 =item A filename
449
450 If the C<$input> parameter is a simple scalar, it is assumed to be a
451 filename. This file will be opened for reading and the input data
452 will be read from it.
453
454 =item A filehandle
455
456 If the C<$input> parameter is a filehandle, the input data will be
457 read from it.
458 The string '-' can be used as an alias for standard input.
459
460 =item A scalar reference 
461
462 If C<$input> is a scalar reference, the input data will be read
463 from C<$$input>.
464
465 =item An array reference 
466
467 If C<$input> is an array reference, each element in the array must be a
468 filename.
469
470 The input data will be read from each file in turn. 
471
472 The complete array will be walked to ensure that it only
473 contains valid filenames before any data is uncompressed.
474
475
476
477 =item An Input FileGlob string
478
479 If C<$input> is a string that is delimited by the characters "<" and ">"
480 C<rawinflate> will assume that it is an I<input fileglob string>. The
481 input is the list of files that match the fileglob.
482
483 If the fileglob does not match any files ...
484
485 See L<File::GlobMapper|File::GlobMapper> for more details.
486
487
488 =back
489
490 If the C<$input> parameter is any other type, C<undef> will be returned.
491
492
493
494 =head3 The C<$output> parameter
495
496 The parameter C<$output> is used to control the destination of the
497 uncompressed data. This parameter can take one of these forms.
498
499 =over 5
500
501 =item A filename
502
503 If the C<$output> parameter is a simple scalar, it is assumed to be a
504 filename.  This file will be opened for writing and the uncompressed
505 data will be written to it.
506
507 =item A filehandle
508
509 If the C<$output> parameter is a filehandle, the uncompressed data
510 will be written to it.
511 The string '-' can be used as an alias for standard output.
512
513
514 =item A scalar reference 
515
516 If C<$output> is a scalar reference, the uncompressed data will be
517 stored in C<$$output>.
518
519
520
521 =item An Array Reference
522
523 If C<$output> is an array reference, the uncompressed data will be
524 pushed onto the array.
525
526 =item An Output FileGlob
527
528 If C<$output> is a string that is delimited by the characters "<" and ">"
529 C<rawinflate> will assume that it is an I<output fileglob string>. The
530 output is the list of files that match the fileglob.
531
532 When C<$output> is an fileglob string, C<$input> must also be a fileglob
533 string. Anything else is an error.
534
535 =back
536
537 If the C<$output> parameter is any other type, C<undef> will be returned.
538
539
540
541 =head2 Notes
542
543
544 When C<$input> maps to multiple compressed files/buffers and C<$output> is
545 a single file/buffer, after uncompression C<$output> will contain a
546 concatenation of all the uncompressed data from each of the input
547 files/buffers.
548
549
550
551
552
553 =head2 Optional Parameters
554
555 Unless specified below, the optional parameters for C<rawinflate>,
556 C<OPTS>, are the same as those used with the OO interface defined in the
557 L</"Constructor Options"> section below.
558
559 =over 5
560
561 =item C<< AutoClose => 0|1 >>
562
563 This option applies to any input or output data streams to 
564 C<rawinflate> that are filehandles.
565
566 If C<AutoClose> is specified, and the value is true, it will result in all
567 input and/or output filehandles being closed once C<rawinflate> has
568 completed.
569
570 This parameter defaults to 0.
571
572
573 =item C<< BinModeOut => 0|1 >>
574
575 When writing to a file or filehandle, set C<binmode> before writing to the
576 file.
577
578 Defaults to 0.
579
580
581
582
583
584 =item C<< Append => 0|1 >>
585
586 TODO
587
588 =item C<< MultiStream => 0|1 >>
589
590
591
592 This option is a no-op.
593
594
595
596
597
598 =item C<< TrailingData => $scalar >>
599
600 Returns the data, if any, that is present immediately after the compressed
601 data stream once uncompression is complete. 
602
603 This option can be used when there is useful information immediately
604 following the compressed data stream, and you don't know the length of the
605 compressed data stream.
606
607 If the input is a buffer, C<trailingData> will return everything from the
608 end of the compressed data stream to the end of the buffer.
609
610 If the input is a filehandle, C<trailingData> will return the data that is
611 left in the filehandle input buffer once the end of the compressed data
612 stream has been reached. You can then use the filehandle to read the rest
613 of the input file. 
614
615 Don't bother using C<trailingData> if the input is a filename.
616
617
618
619 If you know the length of the compressed data stream before you start
620 uncompressing, you can avoid having to use C<trailingData> by setting the
621 C<InputLength> option.
622
623
624
625 =back
626
627
628
629
630 =head2 Examples
631
632 To read the contents of the file C<file1.txt.1951> and write the
633 compressed data to the file C<file1.txt>.
634
635     use strict ;
636     use warnings ;
637     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
638
639     my $input = "file1.txt.1951";
640     my $output = "file1.txt";
641     rawinflate $input => $output
642         or die "rawinflate failed: $RawInflateError\n";
643
644
645 To read from an existing Perl filehandle, C<$input>, and write the
646 uncompressed data to a buffer, C<$buffer>.
647
648     use strict ;
649     use warnings ;
650     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
651     use IO::File ;
652
653     my $input = new IO::File "<file1.txt.1951"
654         or die "Cannot open 'file1.txt.1951': $!\n" ;
655     my $buffer ;
656     rawinflate $input => \$buffer 
657         or die "rawinflate failed: $RawInflateError\n";
658
659 To uncompress all files in the directory "/my/home" that match "*.txt.1951" and store the compressed data in the same directory
660
661     use strict ;
662     use warnings ;
663     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
664
665     rawinflate '</my/home/*.txt.1951>' => '</my/home/#1.txt>'
666         or die "rawinflate failed: $RawInflateError\n";
667
668 and if you want to compress each file one at a time, this will do the trick
669
670     use strict ;
671     use warnings ;
672     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
673
674     for my $input ( glob "/my/home/*.txt.1951" )
675     {
676         my $output = $input;
677         $output =~ s/.1951// ;
678         rawinflate $input => $output 
679             or die "Error compressing '$input': $RawInflateError\n";
680     }
681
682 =head1 OO Interface
683
684 =head2 Constructor
685
686 The format of the constructor for IO::Uncompress::RawInflate is shown below
687
688
689     my $z = new IO::Uncompress::RawInflate $input [OPTS]
690         or die "IO::Uncompress::RawInflate failed: $RawInflateError\n";
691
692 Returns an C<IO::Uncompress::RawInflate> object on success and undef on failure.
693 The variable C<$RawInflateError> will contain an error message on failure.
694
695 If you are running Perl 5.005 or better the object, C<$z>, returned from
696 IO::Uncompress::RawInflate can be used exactly like an L<IO::File|IO::File> filehandle.
697 This means that all normal input file operations can be carried out with
698 C<$z>.  For example, to read a line from a compressed file/buffer you can
699 use either of these forms
700
701     $line = $z->getline();
702     $line = <$z>;
703
704 The mandatory parameter C<$input> is used to determine the source of the
705 compressed data. This parameter can take one of three forms.
706
707 =over 5
708
709 =item A filename
710
711 If the C<$input> parameter is a scalar, it is assumed to be a filename. This
712 file will be opened for reading and the compressed data will be read from it.
713
714 =item A filehandle
715
716 If the C<$input> parameter is a filehandle, the compressed data will be
717 read from it.
718 The string '-' can be used as an alias for standard input.
719
720
721 =item A scalar reference 
722
723 If C<$input> is a scalar reference, the compressed data will be read from
724 C<$$output>.
725
726 =back
727
728 =head2 Constructor Options
729
730
731 The option names defined below are case insensitive and can be optionally
732 prefixed by a '-'.  So all of the following are valid
733
734     -AutoClose
735     -autoclose
736     AUTOCLOSE
737     autoclose
738
739 OPTS is a combination of the following options:
740
741 =over 5
742
743 =item C<< AutoClose => 0|1 >>
744
745 This option is only valid when the C<$input> parameter is a filehandle. If
746 specified, and the value is true, it will result in the file being closed once
747 either the C<close> method is called or the IO::Uncompress::RawInflate object is
748 destroyed.
749
750 This parameter defaults to 0.
751
752 =item C<< MultiStream => 0|1 >>
753
754
755
756 This option is a no-op.
757
758
759
760 =item C<< Prime => $string >>
761
762 This option will uncompress the contents of C<$string> before processing the
763 input file/buffer.
764
765 This option can be useful when the compressed data is embedded in another
766 file/data structure and it is not possible to work out where the compressed
767 data begins without having to read the first few bytes. If this is the
768 case, the uncompression can be I<primed> with these bytes using this
769 option.
770
771 =item C<< Transparent => 0|1 >>
772
773 If this option is set and the input file or buffer is not compressed data,
774 the module will allow reading of it anyway.
775
776 This option defaults to 1.
777
778 =item C<< BlockSize => $num >>
779
780 When reading the compressed input data, IO::Uncompress::RawInflate will read it in
781 blocks of C<$num> bytes.
782
783 This option defaults to 4096.
784
785 =item C<< InputLength => $size >>
786
787 When present this option will limit the number of compressed bytes read
788 from the input file/buffer to C<$size>. This option can be used in the
789 situation where there is useful data directly after the compressed data
790 stream and you know beforehand the exact length of the compressed data
791 stream. 
792
793 This option is mostly used when reading from a filehandle, in which case
794 the file pointer will be left pointing to the first byte directly after the
795 compressed data stream.
796
797
798
799 This option defaults to off.
800
801 =item C<< Append => 0|1 >>
802
803 This option controls what the C<read> method does with uncompressed data.
804
805 If set to 1, all uncompressed data will be appended to the output parameter
806 of the C<read> method.
807
808 If set to 0, the contents of the output parameter of the C<read> method
809 will be overwritten by the uncompressed data.
810
811 Defaults to 0.
812
813 =item C<< Strict => 0|1 >>
814
815
816
817 This option is a no-op.
818
819
820
821
822
823
824
825 =back
826
827 =head2 Examples
828
829 TODO
830
831 =head1 Methods 
832
833 =head2 read
834
835 Usage is
836
837     $status = $z->read($buffer)
838
839 Reads a block of compressed data (the size the the compressed block is
840 determined by the C<Buffer> option in the constructor), uncompresses it and
841 writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
842 set in the constructor, the uncompressed data will be appended to the
843 C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
844
845 Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
846 or a negative number on error.
847
848 =head2 read
849
850 Usage is
851
852     $status = $z->read($buffer, $length)
853     $status = $z->read($buffer, $length, $offset)
854
855     $status = read($z, $buffer, $length)
856     $status = read($z, $buffer, $length, $offset)
857
858 Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
859
860 The main difference between this form of the C<read> method and the
861 previous one, is that this one will attempt to return I<exactly> C<$length>
862 bytes. The only circumstances that this function will not is if end-of-file
863 or an IO error is encountered.
864
865 Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
866 or a negative number on error.
867
868
869 =head2 getline
870
871 Usage is
872
873     $line = $z->getline()
874     $line = <$z>
875
876 Reads a single line. 
877
878 This method fully supports the use of of the variable C<$/> (or
879 C<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to
880 determine what constitutes an end of line. Paragraph mode, record mode and
881 file slurp mode are all supported. 
882
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
899
900 =head2 inflateSync
901
902 Usage is
903
904     $status = $z->inflateSync()
905
906 TODO
907
908
909 =head2 getHeaderInfo
910
911 Usage is
912
913     $hdr  = $z->getHeaderInfo();
914     @hdrs = $z->getHeaderInfo();
915
916 This method returns either a hash reference (in scalar context) or a list
917 or hash references (in array context) that contains information about each
918 of the header fields in the compressed data stream(s).
919
920
921
922
923 =head2 tell
924
925 Usage is
926
927     $z->tell()
928     tell $z
929
930 Returns the uncompressed file offset.
931
932 =head2 eof
933
934 Usage is
935
936     $z->eof();
937     eof($z);
938
939
940
941 Returns true if the end of the compressed input stream has been reached.
942
943
944
945 =head2 seek
946
947     $z->seek($position, $whence);
948     seek($z, $position, $whence);
949
950
951
952
953 Provides a sub-set of the C<seek> functionality, with the restriction
954 that it is only legal to seek forward in the input file/buffer.
955 It is a fatal error to attempt to seek backward.
956
957
958
959 The C<$whence> parameter takes one the usual values, namely SEEK_SET,
960 SEEK_CUR or SEEK_END.
961
962 Returns 1 on success, 0 on failure.
963
964 =head2 binmode
965
966 Usage is
967
968     $z->binmode
969     binmode $z ;
970
971 This is a noop provided for completeness.
972
973 =head2 opened
974
975     $z->opened()
976
977 Returns true if the object currently refers to a opened file/buffer. 
978
979 =head2 autoflush
980
981     my $prev = $z->autoflush()
982     my $prev = $z->autoflush(EXPR)
983
984 If the C<$z> object is associated with a file or a filehandle, this method
985 returns the current autoflush setting for the underlying filehandle. If
986 C<EXPR> is present, and is non-zero, it will enable flushing after every
987 write/print operation.
988
989 If C<$z> is associated with a buffer, this method has no effect and always
990 returns C<undef>.
991
992 B<Note> that the special variable C<$|> B<cannot> be used to set or
993 retrieve the autoflush setting.
994
995 =head2 input_line_number
996
997     $z->input_line_number()
998     $z->input_line_number(EXPR)
999
1000
1001
1002 Returns the current uncompressed line number. If C<EXPR> is present it has
1003 the effect of setting the line number. Note that setting the line number
1004 does not change the current position within the file/buffer being read.
1005
1006 The contents of C<$/> are used to to determine what constitutes a line
1007 terminator.
1008
1009
1010
1011 =head2 fileno
1012
1013     $z->fileno()
1014     fileno($z)
1015
1016 If the C<$z> object is associated with a file or a filehandle, this method
1017 will return the underlying file descriptor.
1018
1019 If the C<$z> object is is associated with a buffer, this method will
1020 return undef.
1021
1022 =head2 close
1023
1024     $z->close() ;
1025     close $z ;
1026
1027
1028
1029 Closes the output file/buffer. 
1030
1031
1032
1033 For most versions of Perl this method will be automatically invoked if
1034 the IO::Uncompress::RawInflate object is destroyed (either explicitly or by the
1035 variable with the reference to the object going out of scope). The
1036 exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In
1037 these cases, the C<close> method will be called automatically, but
1038 not until global destruction of all live objects when the program is
1039 terminating.
1040
1041 Therefore, if you want your scripts to be able to run on all versions
1042 of Perl, you should call C<close> explicitly and not rely on automatic
1043 closing.
1044
1045 Returns true on success, otherwise 0.
1046
1047 If the C<AutoClose> option has been enabled when the IO::Uncompress::RawInflate
1048 object was created, and the object is associated with a file, the
1049 underlying file will also be closed.
1050
1051
1052
1053
1054 =head2 nextStream
1055
1056 Usage is
1057
1058     my $status = $z->nextStream();
1059
1060 Skips to the next compressed data stream in the input file/buffer. If a new
1061 compressed data stream is found, the eof marker will be cleared and C<$.>
1062 will be reset to 0.
1063
1064 Returns 1 if a new stream was found, 0 if none was found, and -1 if an
1065 error was encountered.
1066
1067 =head2 trailingData
1068
1069 Usage is
1070
1071     my $data = $z->trailingData();
1072
1073 Returns the data, if any, that is present immediately after the compressed
1074 data stream once uncompression is complete. It only makes sense to call
1075 this method once the end of the compressed data stream has been
1076 encountered.
1077
1078 This option can be used when there is useful information immediately
1079 following the compressed data stream, and you don't know the length of the
1080 compressed data stream.
1081
1082 If the input is a buffer, C<trailingData> will return everything from the
1083 end of the compressed data stream to the end of the buffer.
1084
1085 If the input is a filehandle, C<trailingData> will return the data that is
1086 left in the filehandle input buffer once the end of the compressed data
1087 stream has been reached. You can then use the filehandle to read the rest
1088 of the input file. 
1089
1090 Don't bother using C<trailingData> if the input is a filename.
1091
1092
1093
1094 If you know the length of the compressed data stream before you start
1095 uncompressing, you can avoid having to use C<trailingData> by setting the
1096 C<InputLength> option in the constructor.
1097
1098 =head1 Importing 
1099
1100 No symbolic constants are required by this IO::Uncompress::RawInflate at present. 
1101
1102 =over 5
1103
1104 =item :all
1105
1106 Imports C<rawinflate> and C<$RawInflateError>.
1107 Same as doing this
1108
1109     use IO::Uncompress::RawInflate qw(rawinflate $RawInflateError) ;
1110
1111 =back
1112
1113 =head1 EXAMPLES
1114
1115
1116
1117
1118 =head1 SEE ALSO
1119
1120 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::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>
1121
1122 L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>
1123
1124 L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,
1125 L<Archive::Tar|Archive::Tar>,
1126 L<IO::Zlib|IO::Zlib>
1127
1128
1129 For RFC 1950, 1951 and 1952 see 
1130 F<http://www.faqs.org/rfcs/rfc1950.html>,
1131 F<http://www.faqs.org/rfcs/rfc1951.html> and
1132 F<http://www.faqs.org/rfcs/rfc1952.html>
1133
1134 The I<zlib> compression library was written by Jean-loup Gailly
1135 F<gzip@prep.ai.mit.edu> and Mark Adler F<madler@alumni.caltech.edu>.
1136
1137 The primary site for the I<zlib> compression library is
1138 F<http://www.zlib.org>.
1139
1140 The primary site for gzip is F<http://www.gzip.org>.
1141
1142
1143
1144
1145 =head1 AUTHOR
1146
1147 This module was written by Paul Marquess, F<pmqs@cpan.org>. 
1148
1149
1150
1151 =head1 MODIFICATION HISTORY
1152
1153 See the Changes file.
1154
1155 =head1 COPYRIGHT AND LICENSE
1156
1157 Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
1158
1159 This program is free software; you can redistribute it and/or
1160 modify it under the same terms as Perl itself.
1161