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