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