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