1b39c5158Smillertpackage IO::Uncompress::AnyUncompress ; 2b39c5158Smillert 3b39c5158Smillertuse strict; 4b39c5158Smillertuse warnings; 5b39c5158Smillertuse bytes; 6b39c5158Smillert 7*3d61058aSafresh1use IO::Compress::Base::Common 2.212 (); 8b39c5158Smillert 9*3d61058aSafresh1use IO::Uncompress::Base 2.212 ; 10b39c5158Smillert 11b39c5158Smillert 12b39c5158Smillertrequire Exporter ; 13b39c5158Smillert 14b39c5158Smillertour ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $AnyUncompressError); 15b39c5158Smillert 16*3d61058aSafresh1$VERSION = '2.212'; 17b39c5158Smillert$AnyUncompressError = ''; 18b39c5158Smillert 199f11ffb7Safresh1@ISA = qw(IO::Uncompress::Base Exporter); 20b39c5158Smillert@EXPORT_OK = qw( $AnyUncompressError anyuncompress ) ; 21eac174f2Safresh1%EXPORT_TAGS = %IO::Uncompress::Base::DEFLATE_CONSTANTS if keys %IO::Uncompress::Base::DEFLATE_CONSTANTS; 22b39c5158Smillertpush @{ $EXPORT_TAGS{all} }, @EXPORT_OK ; 23b39c5158SmillertExporter::export_ok_tags('all'); 24b39c5158Smillert 25b39c5158Smillert# TODO - allow the user to pick a set of the three formats to allow 26b39c5158Smillert# or just assume want to auto-detect any of the three formats. 27b39c5158Smillert 28b39c5158SmillertBEGIN 29b39c5158Smillert{ 300b7734b3Safresh1 local @INC = @INC; 310b7734b3Safresh1 pop @INC if $INC[-1] eq '.'; 32b39c5158Smillert 3356d68f1eSafresh1 # Don't trigger any __DIE__ Hooks. 3456d68f1eSafresh1 local $SIG{__DIE__}; 3556d68f1eSafresh1 36*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::Inflate 2.212 ;'; 37*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::Bunzip2 2.212 ;'; 38*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::LZO 2.212 ;'; 39*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::Lzf 2.212 ;'; 40*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::UnLzma 2.212 ;'; 41*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::UnXz 2.212 ;'; 42*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::UnZstd 2.212 ;'; 43*3d61058aSafresh1 eval ' use IO::Uncompress::Adapter::UnLzip 2.212 ;'; 4456d68f1eSafresh1 45*3d61058aSafresh1 eval ' use IO::Uncompress::Bunzip2 2.212 ;'; 46*3d61058aSafresh1 eval ' use IO::Uncompress::UnLzop 2.212 ;'; 47*3d61058aSafresh1 eval ' use IO::Uncompress::Gunzip 2.212 ;'; 48*3d61058aSafresh1 eval ' use IO::Uncompress::Inflate 2.212 ;'; 49*3d61058aSafresh1 eval ' use IO::Uncompress::RawInflate 2.212 ;'; 50*3d61058aSafresh1 eval ' use IO::Uncompress::Unzip 2.212 ;'; 51*3d61058aSafresh1 eval ' use IO::Uncompress::UnLzf 2.212 ;'; 52*3d61058aSafresh1 eval ' use IO::Uncompress::UnLzma 2.212 ;'; 53*3d61058aSafresh1 eval ' use IO::Uncompress::UnXz 2.212 ;'; 54*3d61058aSafresh1 eval ' use IO::Uncompress::UnZstd 2.212 ;'; 55*3d61058aSafresh1 eval ' use IO::Uncompress::UnLzip 2.212 ;'; 56b46d8ef2Safresh1 57b39c5158Smillert} 58b39c5158Smillert 59b39c5158Smillertsub new 60b39c5158Smillert{ 61b39c5158Smillert my $class = shift ; 6291f110e0Safresh1 my $obj = IO::Compress::Base::Common::createSelfTiedObject($class, \$AnyUncompressError); 63b39c5158Smillert $obj->_create(undef, 0, @_); 64b39c5158Smillert} 65b39c5158Smillert 66b39c5158Smillertsub anyuncompress 67b39c5158Smillert{ 6891f110e0Safresh1 my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$AnyUncompressError); 69b39c5158Smillert return $obj->_inf(@_) ; 70b39c5158Smillert} 71b39c5158Smillert 72b39c5158Smillertsub getExtraParams 73b39c5158Smillert{ 7491f110e0Safresh1 return ( 'rawinflate' => [IO::Compress::Base::Common::Parse_boolean, 0] , 7591f110e0Safresh1 'unlzma' => [IO::Compress::Base::Common::Parse_boolean, 0] ) ; 76b39c5158Smillert} 77b39c5158Smillert 78b39c5158Smillertsub ckParams 79b39c5158Smillert{ 80b39c5158Smillert my $self = shift ; 81b39c5158Smillert my $got = shift ; 82b39c5158Smillert 83b39c5158Smillert # any always needs both crc32 and adler32 8491f110e0Safresh1 $got->setValue('crc32' => 1); 8591f110e0Safresh1 $got->setValue('adler32' => 1); 86b39c5158Smillert 87b39c5158Smillert return 1; 88b39c5158Smillert} 89b39c5158Smillert 90b39c5158Smillertsub mkUncomp 91b39c5158Smillert{ 92b39c5158Smillert my $self = shift ; 93b39c5158Smillert my $got = shift ; 94b39c5158Smillert 95b39c5158Smillert my $magic ; 96b39c5158Smillert 97b39c5158Smillert # try zlib first 98b39c5158Smillert if (defined $IO::Uncompress::RawInflate::VERSION ) 99b39c5158Smillert { 100b39c5158Smillert my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject(); 101b39c5158Smillert 102b39c5158Smillert return $self->saveErrorString(undef, $errstr, $errno) 103b39c5158Smillert if ! defined $obj; 104b39c5158Smillert 105b39c5158Smillert *$self->{Uncomp} = $obj; 106b39c5158Smillert 107b39c5158Smillert my @possible = qw( Inflate Gunzip Unzip ); 108b39c5158Smillert unshift @possible, 'RawInflate' 10991f110e0Safresh1 if $got->getValue('rawinflate'); 110b39c5158Smillert 111b39c5158Smillert $magic = $self->ckMagic( @possible ); 112b39c5158Smillert 113b39c5158Smillert if ($magic) { 114b39c5158Smillert *$self->{Info} = $self->readHeader($magic) 115b39c5158Smillert or return undef ; 116b39c5158Smillert 117b39c5158Smillert return 1; 118b39c5158Smillert } 119b39c5158Smillert } 120b39c5158Smillert 12191f110e0Safresh1 if (defined $IO::Uncompress::UnLzma::VERSION && $got->getValue('unlzma')) 122b39c5158Smillert { 123b39c5158Smillert my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::UnLzma::mkUncompObject(); 124b39c5158Smillert 125b39c5158Smillert return $self->saveErrorString(undef, $errstr, $errno) 126b39c5158Smillert if ! defined $obj; 127b39c5158Smillert 128b39c5158Smillert *$self->{Uncomp} = $obj; 129b39c5158Smillert 130b39c5158Smillert my @possible = qw( UnLzma ); 131b39c5158Smillert #unshift @possible, 'RawInflate' 13291f110e0Safresh1 # if $got->getValue('rawinflate'); 133b39c5158Smillert 134b39c5158Smillert if ( *$self->{Info} = $self->ckMagic( @possible )) 135b39c5158Smillert { 136b39c5158Smillert return 1; 137b39c5158Smillert } 138b39c5158Smillert } 139b39c5158Smillert 140b39c5158Smillert if (defined $IO::Uncompress::UnXz::VERSION and 141b39c5158Smillert $magic = $self->ckMagic('UnXz')) { 142b39c5158Smillert *$self->{Info} = $self->readHeader($magic) 143b39c5158Smillert or return undef ; 144b39c5158Smillert 145b39c5158Smillert my ($obj, $errstr, $errno) = 146b39c5158Smillert IO::Uncompress::Adapter::UnXz::mkUncompObject(); 147b39c5158Smillert 148b39c5158Smillert return $self->saveErrorString(undef, $errstr, $errno) 149b39c5158Smillert if ! defined $obj; 150b39c5158Smillert 151b39c5158Smillert *$self->{Uncomp} = $obj; 152b39c5158Smillert 153b39c5158Smillert return 1; 154b39c5158Smillert } 155b39c5158Smillert 156b39c5158Smillert if (defined $IO::Uncompress::Bunzip2::VERSION and 157b39c5158Smillert $magic = $self->ckMagic('Bunzip2')) { 158b39c5158Smillert *$self->{Info} = $self->readHeader($magic) 159b39c5158Smillert or return undef ; 160b39c5158Smillert 161b39c5158Smillert my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Bunzip2::mkUncompObject(); 162b39c5158Smillert 163b39c5158Smillert return $self->saveErrorString(undef, $errstr, $errno) 164b39c5158Smillert if ! defined $obj; 165b39c5158Smillert 166b39c5158Smillert *$self->{Uncomp} = $obj; 167b39c5158Smillert 168b39c5158Smillert return 1; 169b39c5158Smillert } 170b39c5158Smillert 171b39c5158Smillert if (defined $IO::Uncompress::UnLzop::VERSION and 172b39c5158Smillert $magic = $self->ckMagic('UnLzop')) { 173b39c5158Smillert 174b39c5158Smillert *$self->{Info} = $self->readHeader($magic) 175b39c5158Smillert or return undef ; 176b39c5158Smillert 177b39c5158Smillert my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::LZO::mkUncompObject(); 178b39c5158Smillert 179b39c5158Smillert return $self->saveErrorString(undef, $errstr, $errno) 180b39c5158Smillert if ! defined $obj; 181b39c5158Smillert 182b39c5158Smillert *$self->{Uncomp} = $obj; 183b39c5158Smillert 184b39c5158Smillert return 1; 185b39c5158Smillert } 186b39c5158Smillert 187b39c5158Smillert if (defined $IO::Uncompress::UnLzf::VERSION and 188b39c5158Smillert $magic = $self->ckMagic('UnLzf')) { 189b39c5158Smillert 190b39c5158Smillert *$self->{Info} = $self->readHeader($magic) 191b39c5158Smillert or return undef ; 192b39c5158Smillert 193b39c5158Smillert my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Lzf::mkUncompObject(); 194b39c5158Smillert 195b39c5158Smillert return $self->saveErrorString(undef, $errstr, $errno) 196b39c5158Smillert if ! defined $obj; 197b39c5158Smillert 198b39c5158Smillert *$self->{Uncomp} = $obj; 199b39c5158Smillert 200b39c5158Smillert return 1; 201b39c5158Smillert } 202b39c5158Smillert 203b46d8ef2Safresh1 if (defined $IO::Uncompress::UnZstd::VERSION and 204b46d8ef2Safresh1 $magic = $self->ckMagic('UnZstd')) { 205b46d8ef2Safresh1 206b46d8ef2Safresh1 *$self->{Info} = $self->readHeader($magic) 207b46d8ef2Safresh1 or return undef ; 208b46d8ef2Safresh1 209eac174f2Safresh1 my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::UnZstd::mkUncompObject(); 210b46d8ef2Safresh1 211b46d8ef2Safresh1 return $self->saveErrorString(undef, $errstr, $errno) 212b46d8ef2Safresh1 if ! defined $obj; 213b46d8ef2Safresh1 214b46d8ef2Safresh1 *$self->{Uncomp} = $obj; 215b46d8ef2Safresh1 216b46d8ef2Safresh1 return 1; 217b46d8ef2Safresh1 } 218b46d8ef2Safresh1 219b46d8ef2Safresh1 220b46d8ef2Safresh1 if (defined $IO::Uncompress::UnLzip::VERSION and 221b46d8ef2Safresh1 $magic = $self->ckMagic('UnLzip')) { 222b46d8ef2Safresh1 223b46d8ef2Safresh1 *$self->{Info} = $self->readHeader($magic) 224b46d8ef2Safresh1 or return undef ; 225b46d8ef2Safresh1 226b46d8ef2Safresh1 my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::UnLzip::mkUncompObject(*$self->{Info}{DictSize}); 227b46d8ef2Safresh1 228b46d8ef2Safresh1 return $self->saveErrorString(undef, $errstr, $errno) 229b46d8ef2Safresh1 if ! defined $obj; 230b46d8ef2Safresh1 231b46d8ef2Safresh1 *$self->{Uncomp} = $obj; 232b46d8ef2Safresh1 233b46d8ef2Safresh1 return 1; 234b46d8ef2Safresh1 } 235b46d8ef2Safresh1 236b39c5158Smillert return 0 ; 237b39c5158Smillert} 238b39c5158Smillert 239b39c5158Smillert 240b39c5158Smillert 241b39c5158Smillertsub ckMagic 242b39c5158Smillert{ 243b39c5158Smillert my $self = shift; 244b39c5158Smillert my @names = @_ ; 245b39c5158Smillert 246b39c5158Smillert my $keep = ref $self ; 247b39c5158Smillert for my $class ( map { "IO::Uncompress::$_" } @names) 248b39c5158Smillert { 249b39c5158Smillert bless $self => $class; 250b39c5158Smillert my $magic = $self->ckMagic(); 251b39c5158Smillert 252b39c5158Smillert if ($magic) 253b39c5158Smillert { 254b39c5158Smillert #bless $self => $class; 255b39c5158Smillert return $magic ; 256b39c5158Smillert } 257b39c5158Smillert 258b39c5158Smillert $self->pushBack(*$self->{HeaderPending}) ; 259b39c5158Smillert *$self->{HeaderPending} = '' ; 260b39c5158Smillert } 261b39c5158Smillert 262b39c5158Smillert bless $self => $keep; 263b39c5158Smillert return undef; 264b39c5158Smillert} 265b39c5158Smillert 266b39c5158Smillert1 ; 267b39c5158Smillert 268b39c5158Smillert__END__ 269b39c5158Smillert 270b39c5158Smillert 271b39c5158Smillert=head1 NAME 272b39c5158Smillert 273eac174f2Safresh1IO::Uncompress::AnyUncompress - Uncompress gzip, zip, bzip2, zstd, xz, lzma, lzip, lzf or lzop file/buffer 274b39c5158Smillert 275b39c5158Smillert=head1 SYNOPSIS 276b39c5158Smillert 277b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 278b39c5158Smillert 279b39c5158Smillert my $status = anyuncompress $input => $output [,OPTS] 280b39c5158Smillert or die "anyuncompress failed: $AnyUncompressError\n"; 281b39c5158Smillert 282eac174f2Safresh1 my $z = IO::Uncompress::AnyUncompress->new( $input [OPTS] ) 283b39c5158Smillert or die "anyuncompress failed: $AnyUncompressError\n"; 284b39c5158Smillert 285b39c5158Smillert $status = $z->read($buffer) 286b39c5158Smillert $status = $z->read($buffer, $length) 287b39c5158Smillert $status = $z->read($buffer, $length, $offset) 288b39c5158Smillert $line = $z->getline() 289b39c5158Smillert $char = $z->getc() 290b39c5158Smillert $char = $z->ungetc() 291b39c5158Smillert $char = $z->opened() 292b39c5158Smillert 293b39c5158Smillert $data = $z->trailingData() 294b39c5158Smillert $status = $z->nextStream() 295b39c5158Smillert $data = $z->getHeaderInfo() 296b39c5158Smillert $z->tell() 297b39c5158Smillert $z->seek($position, $whence) 298b39c5158Smillert $z->binmode() 299b39c5158Smillert $z->fileno() 300b39c5158Smillert $z->eof() 301b39c5158Smillert $z->close() 302b39c5158Smillert 303b39c5158Smillert $AnyUncompressError ; 304b39c5158Smillert 305b39c5158Smillert # IO::File mode 306b39c5158Smillert 307b39c5158Smillert <$z> 308b39c5158Smillert read($z, $buffer); 309b39c5158Smillert read($z, $buffer, $length); 310b39c5158Smillert read($z, $buffer, $length, $offset); 311b39c5158Smillert tell($z) 312b39c5158Smillert seek($z, $position, $whence) 313b39c5158Smillert binmode($z) 314b39c5158Smillert fileno($z) 315b39c5158Smillert eof($z) 316b39c5158Smillert close($z) 317b39c5158Smillert 318b39c5158Smillert=head1 DESCRIPTION 319b39c5158Smillert 320b39c5158SmillertThis module provides a Perl interface that allows the reading of 321b39c5158Smillertfiles/buffers that have been compressed with a variety of compression 322b39c5158Smillertlibraries. 323b39c5158Smillert 324b39c5158SmillertThe formats supported are: 325b39c5158Smillert 326b39c5158Smillert=over 5 327b39c5158Smillert 328b39c5158Smillert=item RFC 1950 329b39c5158Smillert 330b39c5158Smillert=item RFC 1951 (optionally) 331b39c5158Smillert 332b39c5158Smillert=item gzip (RFC 1952) 333b39c5158Smillert 334b39c5158Smillert=item zip 335b39c5158Smillert 336eac174f2Safresh1=item zstd (Zstandard) 337eac174f2Safresh1 338b39c5158Smillert=item bzip2 339b39c5158Smillert 340b39c5158Smillert=item lzop 341b39c5158Smillert 342b39c5158Smillert=item lzf 343b39c5158Smillert 344b39c5158Smillert=item lzma 345b39c5158Smillert 346b46d8ef2Safresh1=item lzip 347b46d8ef2Safresh1 348b39c5158Smillert=item xz 349b39c5158Smillert 350b39c5158Smillert=back 351b39c5158Smillert 352b39c5158SmillertThe module will auto-detect which, if any, of the supported 353b39c5158Smillertcompression formats is being used. 354b39c5158Smillert 355b39c5158Smillert=head1 Functional Interface 356b39c5158Smillert 357b39c5158SmillertA top-level function, C<anyuncompress>, is provided to carry out 358b39c5158Smillert"one-shot" uncompression between buffers and/or files. For finer 359b39c5158Smillertcontrol over the uncompression process, see the L</"OO Interface"> 360b39c5158Smillertsection. 361b39c5158Smillert 362b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 363b39c5158Smillert 36491f110e0Safresh1 anyuncompress $input_filename_or_reference => $output_filename_or_reference [,OPTS] 365b39c5158Smillert or die "anyuncompress failed: $AnyUncompressError\n"; 366b39c5158Smillert 367b39c5158SmillertThe functional interface needs Perl5.005 or better. 368b39c5158Smillert 3696fb12b70Safresh1=head2 anyuncompress $input_filename_or_reference => $output_filename_or_reference [, OPTS] 370b39c5158Smillert 37191f110e0Safresh1C<anyuncompress> expects at least two parameters, 37256d68f1eSafresh1C<$input_filename_or_reference> and C<$output_filename_or_reference> 37356d68f1eSafresh1and zero or more optional parameters (see L</Optional Parameters>) 374b39c5158Smillert 37591f110e0Safresh1=head3 The C<$input_filename_or_reference> parameter 376b39c5158Smillert 37791f110e0Safresh1The parameter, C<$input_filename_or_reference>, is used to define the 37891f110e0Safresh1source of the compressed data. 379b39c5158Smillert 380b39c5158SmillertIt can take one of the following forms: 381b39c5158Smillert 382b39c5158Smillert=over 5 383b39c5158Smillert 384b39c5158Smillert=item A filename 385b39c5158Smillert 38656d68f1eSafresh1If the C<$input_filename_or_reference> parameter is a simple scalar, it is 38791f110e0Safresh1assumed to be a filename. This file will be opened for reading and the 38891f110e0Safresh1input data will be read from it. 389b39c5158Smillert 390b39c5158Smillert=item A filehandle 391b39c5158Smillert 39291f110e0Safresh1If the C<$input_filename_or_reference> parameter is a filehandle, the input 39391f110e0Safresh1data will be read from it. The string '-' can be used as an alias for 39491f110e0Safresh1standard input. 395b39c5158Smillert 396b39c5158Smillert=item A scalar reference 397b39c5158Smillert 39891f110e0Safresh1If C<$input_filename_or_reference> is a scalar reference, the input data 39991f110e0Safresh1will be read from C<$$input_filename_or_reference>. 400b39c5158Smillert 401b39c5158Smillert=item An array reference 402b39c5158Smillert 40391f110e0Safresh1If C<$input_filename_or_reference> is an array reference, each element in 40491f110e0Safresh1the array must be a filename. 405b39c5158Smillert 406b39c5158SmillertThe input data will be read from each file in turn. 407b39c5158Smillert 408b39c5158SmillertThe complete array will be walked to ensure that it only 409b39c5158Smillertcontains valid filenames before any data is uncompressed. 410b39c5158Smillert 411b39c5158Smillert=item An Input FileGlob string 412b39c5158Smillert 41391f110e0Safresh1If C<$input_filename_or_reference> is a string that is delimited by the 41491f110e0Safresh1characters "<" and ">" C<anyuncompress> will assume that it is an 41591f110e0Safresh1I<input fileglob string>. The input is the list of files that match the 41691f110e0Safresh1fileglob. 417b39c5158Smillert 418b39c5158SmillertSee L<File::GlobMapper|File::GlobMapper> for more details. 419b39c5158Smillert 420b39c5158Smillert=back 421b39c5158Smillert 42291f110e0Safresh1If the C<$input_filename_or_reference> parameter is any other type, 42391f110e0Safresh1C<undef> will be returned. 424b39c5158Smillert 42591f110e0Safresh1=head3 The C<$output_filename_or_reference> parameter 426b39c5158Smillert 42791f110e0Safresh1The parameter C<$output_filename_or_reference> is used to control the 42891f110e0Safresh1destination of the uncompressed data. This parameter can take one of 42991f110e0Safresh1these forms. 430b39c5158Smillert 431b39c5158Smillert=over 5 432b39c5158Smillert 433b39c5158Smillert=item A filename 434b39c5158Smillert 43591f110e0Safresh1If the C<$output_filename_or_reference> parameter is a simple scalar, it is 43691f110e0Safresh1assumed to be a filename. This file will be opened for writing and the 43791f110e0Safresh1uncompressed data will be written to it. 438b39c5158Smillert 439b39c5158Smillert=item A filehandle 440b39c5158Smillert 44191f110e0Safresh1If the C<$output_filename_or_reference> parameter is a filehandle, the 44291f110e0Safresh1uncompressed data will be written to it. The string '-' can be used as 44391f110e0Safresh1an alias for standard output. 444b39c5158Smillert 445b39c5158Smillert=item A scalar reference 446b39c5158Smillert 44791f110e0Safresh1If C<$output_filename_or_reference> is a scalar reference, the 44891f110e0Safresh1uncompressed data will be stored in C<$$output_filename_or_reference>. 449b39c5158Smillert 450b39c5158Smillert=item An Array Reference 451b39c5158Smillert 45291f110e0Safresh1If C<$output_filename_or_reference> is an array reference, 45391f110e0Safresh1the uncompressed data will be pushed onto the array. 454b39c5158Smillert 455b39c5158Smillert=item An Output FileGlob 456b39c5158Smillert 45791f110e0Safresh1If C<$output_filename_or_reference> is a string that is delimited by the 45891f110e0Safresh1characters "<" and ">" C<anyuncompress> will assume that it is an 45991f110e0Safresh1I<output fileglob string>. The output is the list of files that match the 46091f110e0Safresh1fileglob. 461b39c5158Smillert 46291f110e0Safresh1When C<$output_filename_or_reference> is an fileglob string, 46391f110e0Safresh1C<$input_filename_or_reference> must also be a fileglob string. Anything 46491f110e0Safresh1else is an error. 465b39c5158Smillert 466898184e3SsthenSee L<File::GlobMapper|File::GlobMapper> for more details. 467898184e3Ssthen 468b39c5158Smillert=back 469b39c5158Smillert 47091f110e0Safresh1If the C<$output_filename_or_reference> parameter is any other type, 47191f110e0Safresh1C<undef> will be returned. 472b39c5158Smillert 473b39c5158Smillert=head2 Notes 474b39c5158Smillert 47591f110e0Safresh1When C<$input_filename_or_reference> maps to multiple compressed 47691f110e0Safresh1files/buffers and C<$output_filename_or_reference> is 47791f110e0Safresh1a single file/buffer, after uncompression C<$output_filename_or_reference> will contain a 478b39c5158Smillertconcatenation of all the uncompressed data from each of the input 479b39c5158Smillertfiles/buffers. 480b39c5158Smillert 481b39c5158Smillert=head2 Optional Parameters 482b39c5158Smillert 48356d68f1eSafresh1The optional parameters for the one-shot function C<anyuncompress> 48456d68f1eSafresh1are (for the most part) identical to those used with the OO interface defined in the 48556d68f1eSafresh1L</"Constructor Options"> section. The exceptions are listed below 486b39c5158Smillert 487b39c5158Smillert=over 5 488b39c5158Smillert 489b39c5158Smillert=item C<< AutoClose => 0|1 >> 490b39c5158Smillert 491b39c5158SmillertThis option applies to any input or output data streams to 492b39c5158SmillertC<anyuncompress> that are filehandles. 493b39c5158Smillert 494b39c5158SmillertIf C<AutoClose> is specified, and the value is true, it will result in all 495b39c5158Smillertinput and/or output filehandles being closed once C<anyuncompress> has 496b39c5158Smillertcompleted. 497b39c5158Smillert 498b39c5158SmillertThis parameter defaults to 0. 499b39c5158Smillert 500b39c5158Smillert=item C<< BinModeOut => 0|1 >> 501b39c5158Smillert 502b46d8ef2Safresh1This option is now a no-op. All files will be written in binmode. 503b39c5158Smillert 504b39c5158Smillert=item C<< Append => 0|1 >> 505b39c5158Smillert 506b39c5158SmillertThe behaviour of this option is dependent on the type of output data 507b39c5158Smillertstream. 508b39c5158Smillert 509b39c5158Smillert=over 5 510b39c5158Smillert 511b39c5158Smillert=item * A Buffer 512b39c5158Smillert 513b39c5158SmillertIf C<Append> is enabled, all uncompressed data will be append to the end of 514b39c5158Smillertthe output buffer. Otherwise the output buffer will be cleared before any 515b39c5158Smillertuncompressed data is written to it. 516b39c5158Smillert 517b39c5158Smillert=item * A Filename 518b39c5158Smillert 519b39c5158SmillertIf C<Append> is enabled, the file will be opened in append mode. Otherwise 520b39c5158Smillertthe contents of the file, if any, will be truncated before any uncompressed 521b39c5158Smillertdata is written to it. 522b39c5158Smillert 523b39c5158Smillert=item * A Filehandle 524b39c5158Smillert 525b39c5158SmillertIf C<Append> is enabled, the filehandle will be positioned to the end of 526b39c5158Smillertthe file via a call to C<seek> before any uncompressed data is 527b39c5158Smillertwritten to it. Otherwise the file pointer will not be moved. 528b39c5158Smillert 529b39c5158Smillert=back 530b39c5158Smillert 531b39c5158SmillertWhen C<Append> is specified, and set to true, it will I<append> all uncompressed 532b39c5158Smillertdata to the output data stream. 533b39c5158Smillert 534b39c5158SmillertSo when the output is a filehandle it will carry out a seek to the eof 535b39c5158Smillertbefore writing any uncompressed data. If the output is a filename, it will be opened for 536898184e3Ssthenappending. If the output is a buffer, all uncompressed data will be 537898184e3Ssthenappended to the existing buffer. 538b39c5158Smillert 539b39c5158SmillertConversely when C<Append> is not specified, or it is present and is set to 540b39c5158Smillertfalse, it will operate as follows. 541b39c5158Smillert 542b39c5158SmillertWhen the output is a filename, it will truncate the contents of the file 543b39c5158Smillertbefore writing any uncompressed data. If the output is a filehandle 544b39c5158Smillertits position will not be changed. If the output is a buffer, it will be 545b39c5158Smillertwiped before any uncompressed data is output. 546b39c5158Smillert 547b39c5158SmillertDefaults to 0. 548b39c5158Smillert 549b39c5158Smillert=item C<< MultiStream => 0|1 >> 550b39c5158Smillert 551b39c5158SmillertIf the input file/buffer contains multiple compressed data streams, this 552b39c5158Smillertoption will uncompress the whole lot as a single data stream. 553b39c5158Smillert 554b39c5158SmillertDefaults to 0. 555b39c5158Smillert 556b39c5158Smillert=item C<< TrailingData => $scalar >> 557b39c5158Smillert 558b39c5158SmillertReturns the data, if any, that is present immediately after the compressed 559b39c5158Smillertdata stream once uncompression is complete. 560b39c5158Smillert 561b39c5158SmillertThis option can be used when there is useful information immediately 562b39c5158Smillertfollowing the compressed data stream, and you don't know the length of the 563b39c5158Smillertcompressed data stream. 564b39c5158Smillert 565b39c5158SmillertIf the input is a buffer, C<trailingData> will return everything from the 566b39c5158Smillertend of the compressed data stream to the end of the buffer. 567b39c5158Smillert 568b39c5158SmillertIf the input is a filehandle, C<trailingData> will return the data that is 569b39c5158Smillertleft in the filehandle input buffer once the end of the compressed data 570b39c5158Smillertstream has been reached. You can then use the filehandle to read the rest 571b39c5158Smillertof the input file. 572b39c5158Smillert 573b39c5158SmillertDon't bother using C<trailingData> if the input is a filename. 574b39c5158Smillert 575b39c5158SmillertIf you know the length of the compressed data stream before you start 576b39c5158Smillertuncompressing, you can avoid having to use C<trailingData> by setting the 577b39c5158SmillertC<InputLength> option. 578b39c5158Smillert 579b39c5158Smillert=back 580b39c5158Smillert 581*3d61058aSafresh1=head2 OneShot Examples 582b39c5158Smillert 583b39c5158SmillertTo read the contents of the file C<file1.txt.Compressed> and write the 584b39c5158Smillertuncompressed data to the file C<file1.txt>. 585b39c5158Smillert 586b39c5158Smillert use strict ; 587b39c5158Smillert use warnings ; 588b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 589b39c5158Smillert 590b39c5158Smillert my $input = "file1.txt.Compressed"; 591b39c5158Smillert my $output = "file1.txt"; 592b39c5158Smillert anyuncompress $input => $output 593b39c5158Smillert or die "anyuncompress failed: $AnyUncompressError\n"; 594b39c5158Smillert 595b39c5158SmillertTo read from an existing Perl filehandle, C<$input>, and write the 596b39c5158Smillertuncompressed data to a buffer, C<$buffer>. 597b39c5158Smillert 598b39c5158Smillert use strict ; 599b39c5158Smillert use warnings ; 600b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 601b39c5158Smillert use IO::File ; 602b39c5158Smillert 603eac174f2Safresh1 my $input = IO::File->new( "<file1.txt.Compressed" ) 604b39c5158Smillert or die "Cannot open 'file1.txt.Compressed': $!\n" ; 605b39c5158Smillert my $buffer ; 606b39c5158Smillert anyuncompress $input => \$buffer 607b39c5158Smillert or die "anyuncompress failed: $AnyUncompressError\n"; 608b39c5158Smillert 609b39c5158SmillertTo uncompress all files in the directory "/my/home" that match "*.txt.Compressed" and store the compressed data in the same directory 610b39c5158Smillert 611b39c5158Smillert use strict ; 612b39c5158Smillert use warnings ; 613b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 614b39c5158Smillert 615b39c5158Smillert anyuncompress '</my/home/*.txt.Compressed>' => '</my/home/#1.txt>' 616b39c5158Smillert or die "anyuncompress failed: $AnyUncompressError\n"; 617b39c5158Smillert 618b39c5158Smillertand if you want to compress each file one at a time, this will do the trick 619b39c5158Smillert 620b39c5158Smillert use strict ; 621b39c5158Smillert use warnings ; 622b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 623b39c5158Smillert 624b39c5158Smillert for my $input ( glob "/my/home/*.txt.Compressed" ) 625b39c5158Smillert { 626b39c5158Smillert my $output = $input; 627b39c5158Smillert $output =~ s/.Compressed// ; 628b39c5158Smillert anyuncompress $input => $output 629b39c5158Smillert or die "Error compressing '$input': $AnyUncompressError\n"; 630b39c5158Smillert } 631b39c5158Smillert 632b39c5158Smillert=head1 OO Interface 633b39c5158Smillert 634b39c5158Smillert=head2 Constructor 635b39c5158Smillert 636b39c5158SmillertThe format of the constructor for IO::Uncompress::AnyUncompress is shown below 637b39c5158Smillert 638eac174f2Safresh1 my $z = IO::Uncompress::AnyUncompress->new( $input [OPTS] ) 639b39c5158Smillert or die "IO::Uncompress::AnyUncompress failed: $AnyUncompressError\n"; 640b39c5158Smillert 641*3d61058aSafresh1The constructor takes one mandatory parameter, C<$input>, defined below, and 642*3d61058aSafresh1zero or more C<OPTS>, defined in L<Constructor Options>. 643*3d61058aSafresh1 644b39c5158SmillertReturns an C<IO::Uncompress::AnyUncompress> object on success and undef on failure. 645b39c5158SmillertThe variable C<$AnyUncompressError> will contain an error message on failure. 646b39c5158Smillert 647b39c5158SmillertIf you are running Perl 5.005 or better the object, C<$z>, returned from 648b39c5158SmillertIO::Uncompress::AnyUncompress can be used exactly like an L<IO::File|IO::File> filehandle. 649b39c5158SmillertThis means that all normal input file operations can be carried out with 650b39c5158SmillertC<$z>. For example, to read a line from a compressed file/buffer you can 651b39c5158Smillertuse either of these forms 652b39c5158Smillert 653b39c5158Smillert $line = $z->getline(); 654b39c5158Smillert $line = <$z>; 655b39c5158Smillert 656*3d61058aSafresh1Below is a simple exaple of using the OO interface to read the compressed file 657*3d61058aSafresh1C<myfile.Compressed> and write its contents to stdout. 658*3d61058aSafresh1 659*3d61058aSafresh1 my $filename = "myfile.Compressed"; 660*3d61058aSafresh1 my $z = IO::Uncompress::AnyUncompress->new($filename) 661*3d61058aSafresh1 or die "IO::Uncompress::AnyUncompress failed: $AnyUncompressError\n"; 662*3d61058aSafresh1 663*3d61058aSafresh1 while (<$z>) { 664*3d61058aSafresh1 print $_; 665*3d61058aSafresh1 } 666*3d61058aSafresh1 $z->close(); 667*3d61058aSafresh1 668*3d61058aSafresh1See L</EXAMPLES> for further examples 669*3d61058aSafresh1 670b39c5158SmillertThe mandatory parameter C<$input> is used to determine the source of the 671b39c5158Smillertcompressed data. This parameter can take one of three forms. 672b39c5158Smillert 673b39c5158Smillert=over 5 674b39c5158Smillert 675b39c5158Smillert=item A filename 676b39c5158Smillert 677b39c5158SmillertIf the C<$input> parameter is a scalar, it is assumed to be a filename. This 678b39c5158Smillertfile will be opened for reading and the compressed data will be read from it. 679b39c5158Smillert 680b39c5158Smillert=item A filehandle 681b39c5158Smillert 682b39c5158SmillertIf the C<$input> parameter is a filehandle, the compressed data will be 683b39c5158Smillertread from it. 684b39c5158SmillertThe string '-' can be used as an alias for standard input. 685b39c5158Smillert 686b39c5158Smillert=item A scalar reference 687b39c5158Smillert 688b39c5158SmillertIf C<$input> is a scalar reference, the compressed data will be read from 68991f110e0Safresh1C<$$input>. 690b39c5158Smillert 691b39c5158Smillert=back 692b39c5158Smillert 693b39c5158Smillert=head2 Constructor Options 694b39c5158Smillert 695b39c5158SmillertThe option names defined below are case insensitive and can be optionally 696b39c5158Smillertprefixed by a '-'. So all of the following are valid 697b39c5158Smillert 698b39c5158Smillert -AutoClose 699b39c5158Smillert -autoclose 700b39c5158Smillert AUTOCLOSE 701b39c5158Smillert autoclose 702b39c5158Smillert 703b39c5158SmillertOPTS is a combination of the following options: 704b39c5158Smillert 705b39c5158Smillert=over 5 706b39c5158Smillert 707b39c5158Smillert=item C<< AutoClose => 0|1 >> 708b39c5158Smillert 709b39c5158SmillertThis option is only valid when the C<$input> parameter is a filehandle. If 710b39c5158Smillertspecified, and the value is true, it will result in the file being closed once 711b39c5158Smillerteither the C<close> method is called or the IO::Uncompress::AnyUncompress object is 712b39c5158Smillertdestroyed. 713b39c5158Smillert 714b39c5158SmillertThis parameter defaults to 0. 715b39c5158Smillert 716b39c5158Smillert=item C<< MultiStream => 0|1 >> 717b39c5158Smillert 718b39c5158SmillertAllows multiple concatenated compressed streams to be treated as a single 719b39c5158Smillertcompressed stream. Decompression will stop once either the end of the 720b39c5158Smillertfile/buffer is reached, an error is encountered (premature eof, corrupt 721b39c5158Smillertcompressed data) or the end of a stream is not immediately followed by the 722b39c5158Smillertstart of another stream. 723b39c5158Smillert 724b39c5158SmillertThis parameter defaults to 0. 725b39c5158Smillert 726b39c5158Smillert=item C<< Prime => $string >> 727b39c5158Smillert 728b39c5158SmillertThis option will uncompress the contents of C<$string> before processing the 729b39c5158Smillertinput file/buffer. 730b39c5158Smillert 731b39c5158SmillertThis option can be useful when the compressed data is embedded in another 732b39c5158Smillertfile/data structure and it is not possible to work out where the compressed 733b39c5158Smillertdata begins without having to read the first few bytes. If this is the 734b39c5158Smillertcase, the uncompression can be I<primed> with these bytes using this 735b39c5158Smillertoption. 736b39c5158Smillert 737b39c5158Smillert=item C<< Transparent => 0|1 >> 738b39c5158Smillert 739b39c5158SmillertIf this option is set and the input file/buffer is not compressed data, 740b39c5158Smillertthe module will allow reading of it anyway. 741b39c5158Smillert 742b39c5158SmillertIn addition, if the input file/buffer does contain compressed data and 743b39c5158Smillertthere is non-compressed data immediately following it, setting this option 744898184e3Ssthenwill make this module treat the whole file/buffer as a single data stream. 745b39c5158Smillert 746b39c5158SmillertThis option defaults to 1. 747b39c5158Smillert 748b39c5158Smillert=item C<< BlockSize => $num >> 749b39c5158Smillert 750b39c5158SmillertWhen reading the compressed input data, IO::Uncompress::AnyUncompress will read it in 751b39c5158Smillertblocks of C<$num> bytes. 752b39c5158Smillert 753b39c5158SmillertThis option defaults to 4096. 754b39c5158Smillert 755b39c5158Smillert=item C<< InputLength => $size >> 756b39c5158Smillert 757b39c5158SmillertWhen present this option will limit the number of compressed bytes read 758b39c5158Smillertfrom the input file/buffer to C<$size>. This option can be used in the 759b39c5158Smillertsituation where there is useful data directly after the compressed data 760b39c5158Smillertstream and you know beforehand the exact length of the compressed data 761b39c5158Smillertstream. 762b39c5158Smillert 763b39c5158SmillertThis option is mostly used when reading from a filehandle, in which case 764b39c5158Smillertthe file pointer will be left pointing to the first byte directly after the 765b39c5158Smillertcompressed data stream. 766b39c5158Smillert 767b39c5158SmillertThis option defaults to off. 768b39c5158Smillert 769b39c5158Smillert=item C<< Append => 0|1 >> 770b39c5158Smillert 771b39c5158SmillertThis option controls what the C<read> method does with uncompressed data. 772b39c5158Smillert 773b39c5158SmillertIf set to 1, all uncompressed data will be appended to the output parameter 774b39c5158Smillertof the C<read> method. 775b39c5158Smillert 776b39c5158SmillertIf set to 0, the contents of the output parameter of the C<read> method 777b39c5158Smillertwill be overwritten by the uncompressed data. 778b39c5158Smillert 779b39c5158SmillertDefaults to 0. 780b39c5158Smillert 781b39c5158Smillert=item C<< Strict => 0|1 >> 782b39c5158Smillert 783b39c5158SmillertThis option controls whether the extra checks defined below are used when 784b39c5158Smillertcarrying out the decompression. When Strict is on, the extra tests are 785b39c5158Smillertcarried out, when Strict is off they are not. 786b39c5158Smillert 787b39c5158SmillertThe default for this option is off. 788b39c5158Smillert 789b39c5158Smillert=item C<< RawInflate => 0|1 >> 790b39c5158Smillert 791b39c5158SmillertWhen auto-detecting the compressed format, try to test for raw-deflate (RFC 792b39c5158Smillert1951) content using the C<IO::Uncompress::RawInflate> module. 793b39c5158Smillert 794b39c5158SmillertThe reason this is not default behaviour is because RFC 1951 content can 795b39c5158Smillertonly be detected by attempting to uncompress it. This process is error 796b39c5158Smillertprone and can result is false positives. 797b39c5158Smillert 798b39c5158SmillertDefaults to 0. 799b39c5158Smillert 800b39c5158Smillert=item C<< UnLzma => 0|1 >> 801b39c5158Smillert 802b39c5158SmillertWhen auto-detecting the compressed format, try to test for lzma_alone 803b39c5158Smillertcontent using the C<IO::Uncompress::UnLzma> module. 804b39c5158Smillert 805b39c5158SmillertThe reason this is not default behaviour is because lzma_alone content can 806b39c5158Smillertonly be detected by attempting to uncompress it. This process is error 807b39c5158Smillertprone and can result is false positives. 808b39c5158Smillert 809b39c5158SmillertDefaults to 0. 810b39c5158Smillert 811b39c5158Smillert=back 812b39c5158Smillert 813b39c5158Smillert=head1 Methods 814b39c5158Smillert 815b39c5158Smillert=head2 read 816b39c5158Smillert 817b39c5158SmillertUsage is 818b39c5158Smillert 819b39c5158Smillert $status = $z->read($buffer) 820b39c5158Smillert 8216fb12b70Safresh1Reads a block of compressed data (the size of the compressed block is 822b39c5158Smillertdetermined by the C<Buffer> option in the constructor), uncompresses it and 823b39c5158Smillertwrites any uncompressed data into C<$buffer>. If the C<Append> parameter is 824b39c5158Smillertset in the constructor, the uncompressed data will be appended to the 825b39c5158SmillertC<$buffer> parameter. Otherwise C<$buffer> will be overwritten. 826b39c5158Smillert 827b39c5158SmillertReturns the number of uncompressed bytes written to C<$buffer>, zero if eof 828b39c5158Smillertor a negative number on error. 829b39c5158Smillert 830b39c5158Smillert=head2 read 831b39c5158Smillert 832b39c5158SmillertUsage is 833b39c5158Smillert 834b39c5158Smillert $status = $z->read($buffer, $length) 835b39c5158Smillert $status = $z->read($buffer, $length, $offset) 836b39c5158Smillert 837b39c5158Smillert $status = read($z, $buffer, $length) 838b39c5158Smillert $status = read($z, $buffer, $length, $offset) 839b39c5158Smillert 840b39c5158SmillertAttempt to read C<$length> bytes of uncompressed data into C<$buffer>. 841b39c5158Smillert 842b39c5158SmillertThe main difference between this form of the C<read> method and the 843b39c5158Smillertprevious one, is that this one will attempt to return I<exactly> C<$length> 844b39c5158Smillertbytes. The only circumstances that this function will not is if end-of-file 845b39c5158Smillertor an IO error is encountered. 846b39c5158Smillert 847b39c5158SmillertReturns the number of uncompressed bytes written to C<$buffer>, zero if eof 848b39c5158Smillertor a negative number on error. 849b39c5158Smillert 850b39c5158Smillert=head2 getline 851b39c5158Smillert 852b39c5158SmillertUsage is 853b39c5158Smillert 854b39c5158Smillert $line = $z->getline() 855b39c5158Smillert $line = <$z> 856b39c5158Smillert 857b39c5158SmillertReads a single line. 858b39c5158Smillert 8596fb12b70Safresh1This method fully supports the use of the variable C<$/> (or 860b39c5158SmillertC<$INPUT_RECORD_SEPARATOR> or C<$RS> when C<English> is in use) to 861b39c5158Smillertdetermine what constitutes an end of line. Paragraph mode, record mode and 862b39c5158Smillertfile slurp mode are all supported. 863b39c5158Smillert 864b39c5158Smillert=head2 getc 865b39c5158Smillert 866b39c5158SmillertUsage is 867b39c5158Smillert 868b39c5158Smillert $char = $z->getc() 869b39c5158Smillert 870b39c5158SmillertRead a single character. 871b39c5158Smillert 872b39c5158Smillert=head2 ungetc 873b39c5158Smillert 874b39c5158SmillertUsage is 875b39c5158Smillert 876b39c5158Smillert $char = $z->ungetc($string) 877b39c5158Smillert 878b39c5158Smillert=head2 getHeaderInfo 879b39c5158Smillert 880b39c5158SmillertUsage is 881b39c5158Smillert 882b39c5158Smillert $hdr = $z->getHeaderInfo(); 883b39c5158Smillert @hdrs = $z->getHeaderInfo(); 884b39c5158Smillert 885b39c5158SmillertThis method returns either a hash reference (in scalar context) or a list 886b39c5158Smillertor hash references (in array context) that contains information about each 887b39c5158Smillertof the header fields in the compressed data stream(s). 888b39c5158Smillert 889b39c5158Smillert=head2 tell 890b39c5158Smillert 891b39c5158SmillertUsage is 892b39c5158Smillert 893b39c5158Smillert $z->tell() 894b39c5158Smillert tell $z 895b39c5158Smillert 896b39c5158SmillertReturns the uncompressed file offset. 897b39c5158Smillert 898b39c5158Smillert=head2 eof 899b39c5158Smillert 900b39c5158SmillertUsage is 901b39c5158Smillert 902b39c5158Smillert $z->eof(); 903b39c5158Smillert eof($z); 904b39c5158Smillert 905b39c5158SmillertReturns true if the end of the compressed input stream has been reached. 906b39c5158Smillert 907b39c5158Smillert=head2 seek 908b39c5158Smillert 909b39c5158Smillert $z->seek($position, $whence); 910b39c5158Smillert seek($z, $position, $whence); 911b39c5158Smillert 912b39c5158SmillertProvides a sub-set of the C<seek> functionality, with the restriction 913b39c5158Smillertthat it is only legal to seek forward in the input file/buffer. 914b39c5158SmillertIt is a fatal error to attempt to seek backward. 915b39c5158Smillert 91691f110e0Safresh1Note that the implementation of C<seek> in this module does not provide 91791f110e0Safresh1true random access to a compressed file/buffer. It works by uncompressing 91891f110e0Safresh1data from the current offset in the file/buffer until it reaches the 9196fb12b70Safresh1uncompressed offset specified in the parameters to C<seek>. For very small 92091f110e0Safresh1files this may be acceptable behaviour. For large files it may cause an 92191f110e0Safresh1unacceptable delay. 92291f110e0Safresh1 923b39c5158SmillertThe C<$whence> parameter takes one the usual values, namely SEEK_SET, 924b39c5158SmillertSEEK_CUR or SEEK_END. 925b39c5158Smillert 926b39c5158SmillertReturns 1 on success, 0 on failure. 927b39c5158Smillert 928b39c5158Smillert=head2 binmode 929b39c5158Smillert 930b39c5158SmillertUsage is 931b39c5158Smillert 932b39c5158Smillert $z->binmode 933b39c5158Smillert binmode $z ; 934b39c5158Smillert 935b39c5158SmillertThis is a noop provided for completeness. 936b39c5158Smillert 937b39c5158Smillert=head2 opened 938b39c5158Smillert 939b39c5158Smillert $z->opened() 940b39c5158Smillert 941b39c5158SmillertReturns true if the object currently refers to a opened file/buffer. 942b39c5158Smillert 943b39c5158Smillert=head2 autoflush 944b39c5158Smillert 945b39c5158Smillert my $prev = $z->autoflush() 946b39c5158Smillert my $prev = $z->autoflush(EXPR) 947b39c5158Smillert 948b39c5158SmillertIf the C<$z> object is associated with a file or a filehandle, this method 949b39c5158Smillertreturns the current autoflush setting for the underlying filehandle. If 950b39c5158SmillertC<EXPR> is present, and is non-zero, it will enable flushing after every 951b39c5158Smillertwrite/print operation. 952b39c5158Smillert 953b39c5158SmillertIf C<$z> is associated with a buffer, this method has no effect and always 954b39c5158Smillertreturns C<undef>. 955b39c5158Smillert 956b39c5158SmillertB<Note> that the special variable C<$|> B<cannot> be used to set or 957b39c5158Smillertretrieve the autoflush setting. 958b39c5158Smillert 959b39c5158Smillert=head2 input_line_number 960b39c5158Smillert 961b39c5158Smillert $z->input_line_number() 962b39c5158Smillert $z->input_line_number(EXPR) 963b39c5158Smillert 964b39c5158SmillertReturns the current uncompressed line number. If C<EXPR> is present it has 965b39c5158Smillertthe effect of setting the line number. Note that setting the line number 966b39c5158Smillertdoes not change the current position within the file/buffer being read. 967b39c5158Smillert 9686fb12b70Safresh1The contents of C<$/> are used to determine what constitutes a line 969b39c5158Smillertterminator. 970b39c5158Smillert 971b39c5158Smillert=head2 fileno 972b39c5158Smillert 973b39c5158Smillert $z->fileno() 974b39c5158Smillert fileno($z) 975b39c5158Smillert 976b39c5158SmillertIf the C<$z> object is associated with a file or a filehandle, C<fileno> 977b39c5158Smillertwill return the underlying file descriptor. Once the C<close> method is 978b39c5158Smillertcalled C<fileno> will return C<undef>. 979b39c5158Smillert 980898184e3SsthenIf the C<$z> object is associated with a buffer, this method will return 981b39c5158SmillertC<undef>. 982b39c5158Smillert 983b39c5158Smillert=head2 close 984b39c5158Smillert 985b39c5158Smillert $z->close() ; 986b39c5158Smillert close $z ; 987b39c5158Smillert 988b39c5158SmillertCloses the output file/buffer. 989b39c5158Smillert 990b39c5158SmillertFor most versions of Perl this method will be automatically invoked if 991b39c5158Smillertthe IO::Uncompress::AnyUncompress object is destroyed (either explicitly or by the 992b39c5158Smillertvariable with the reference to the object going out of scope). The 993b39c5158Smillertexceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In 994b39c5158Smillertthese cases, the C<close> method will be called automatically, but 995b39c5158Smillertnot until global destruction of all live objects when the program is 996b39c5158Smillertterminating. 997b39c5158Smillert 998b39c5158SmillertTherefore, if you want your scripts to be able to run on all versions 999b39c5158Smillertof Perl, you should call C<close> explicitly and not rely on automatic 1000b39c5158Smillertclosing. 1001b39c5158Smillert 1002b39c5158SmillertReturns true on success, otherwise 0. 1003b39c5158Smillert 1004b39c5158SmillertIf the C<AutoClose> option has been enabled when the IO::Uncompress::AnyUncompress 1005b39c5158Smillertobject was created, and the object is associated with a file, the 1006b39c5158Smillertunderlying file will also be closed. 1007b39c5158Smillert 1008b39c5158Smillert=head2 nextStream 1009b39c5158Smillert 1010b39c5158SmillertUsage is 1011b39c5158Smillert 1012b39c5158Smillert my $status = $z->nextStream(); 1013b39c5158Smillert 1014b39c5158SmillertSkips to the next compressed data stream in the input file/buffer. If a new 1015b39c5158Smillertcompressed data stream is found, the eof marker will be cleared and C<$.> 1016b39c5158Smillertwill be reset to 0. 1017b39c5158Smillert 1018b39c5158SmillertReturns 1 if a new stream was found, 0 if none was found, and -1 if an 1019b39c5158Smillerterror was encountered. 1020b39c5158Smillert 1021b39c5158Smillert=head2 trailingData 1022b39c5158Smillert 1023b39c5158SmillertUsage is 1024b39c5158Smillert 1025b39c5158Smillert my $data = $z->trailingData(); 1026b39c5158Smillert 1027b39c5158SmillertReturns the data, if any, that is present immediately after the compressed 1028b39c5158Smillertdata stream once uncompression is complete. It only makes sense to call 1029b39c5158Smillertthis method once the end of the compressed data stream has been 1030b39c5158Smillertencountered. 1031b39c5158Smillert 1032b39c5158SmillertThis option can be used when there is useful information immediately 1033b39c5158Smillertfollowing the compressed data stream, and you don't know the length of the 1034b39c5158Smillertcompressed data stream. 1035b39c5158Smillert 1036b39c5158SmillertIf the input is a buffer, C<trailingData> will return everything from the 1037b39c5158Smillertend of the compressed data stream to the end of the buffer. 1038b39c5158Smillert 1039b39c5158SmillertIf the input is a filehandle, C<trailingData> will return the data that is 1040b39c5158Smillertleft in the filehandle input buffer once the end of the compressed data 1041b39c5158Smillertstream has been reached. You can then use the filehandle to read the rest 1042b39c5158Smillertof the input file. 1043b39c5158Smillert 1044b39c5158SmillertDon't bother using C<trailingData> if the input is a filename. 1045b39c5158Smillert 1046b39c5158SmillertIf you know the length of the compressed data stream before you start 1047b39c5158Smillertuncompressing, you can avoid having to use C<trailingData> by setting the 1048b39c5158SmillertC<InputLength> option in the constructor. 1049b39c5158Smillert 1050b39c5158Smillert=head1 Importing 1051b39c5158Smillert 1052eac174f2Safresh1No symbolic constants are required by IO::Uncompress::AnyUncompress at present. 1053b39c5158Smillert 1054b39c5158Smillert=over 5 1055b39c5158Smillert 1056b39c5158Smillert=item :all 1057b39c5158Smillert 1058b39c5158SmillertImports C<anyuncompress> and C<$AnyUncompressError>. 1059b39c5158SmillertSame as doing this 1060b39c5158Smillert 1061b39c5158Smillert use IO::Uncompress::AnyUncompress qw(anyuncompress $AnyUncompressError) ; 1062b39c5158Smillert 1063b39c5158Smillert=back 1064b39c5158Smillert 1065b39c5158Smillert=head1 EXAMPLES 1066b39c5158Smillert 106756d68f1eSafresh1=head1 SUPPORT 106856d68f1eSafresh1 106956d68f1eSafresh1General feedback/questions/bug reports should be sent to 107056d68f1eSafresh1L<https://github.com/pmqs/IO-Compress/issues> (preferred) or 107156d68f1eSafresh1L<https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress>. 107256d68f1eSafresh1 1073b39c5158Smillert=head1 SEE ALSO 1074b39c5158Smillert 1075b46d8ef2Safresh1L<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::Lzip>, L<IO::Uncompress::UnLzip>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Compress::Zstd>, L<IO::Uncompress::UnZstd>, L<IO::Uncompress::AnyInflate> 1076b39c5158Smillert 1077898184e3SsthenL<IO::Compress::FAQ|IO::Compress::FAQ> 1078b39c5158Smillert 1079b39c5158SmillertL<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>, 1080b39c5158SmillertL<Archive::Tar|Archive::Tar>, 1081b39c5158SmillertL<IO::Zlib|IO::Zlib> 1082b39c5158Smillert 1083b39c5158Smillert=head1 AUTHOR 1084b39c5158Smillert 10859f11ffb7Safresh1This module was written by Paul Marquess, C<pmqs@cpan.org>. 1086b39c5158Smillert 1087b39c5158Smillert=head1 MODIFICATION HISTORY 1088b39c5158Smillert 1089b39c5158SmillertSee the Changes file. 1090b39c5158Smillert 1091b39c5158Smillert=head1 COPYRIGHT AND LICENSE 1092b39c5158Smillert 1093*3d61058aSafresh1Copyright (c) 2005-2024 Paul Marquess. All rights reserved. 1094b39c5158Smillert 1095b39c5158SmillertThis program is free software; you can redistribute it and/or 1096b39c5158Smillertmodify it under the same terms as Perl itself. 1097