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