package IO::Uncompress::AnyInflate ;
# for RFC1950, RFC1951 or RFC1952
use strict;
use warnings;
use bytes;
use IO::Compress::Base::Common 2.021 qw(createSelfTiedObject);
use IO::Uncompress::Adapter::Inflate 2.021 ();
use IO::Uncompress::Base 2.021 ;
use IO::Uncompress::Gunzip 2.021 ;
use IO::Uncompress::Inflate 2.021 ;
use IO::Uncompress::RawInflate 2.021 ;
use IO::Uncompress::Unzip 2.021 ;
require Exporter ;
our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $AnyInflateError);
$VERSION = '2.021';
$AnyInflateError = '';
@ISA = qw( Exporter IO::Uncompress::Base );
@EXPORT_OK = qw( $AnyInflateError anyinflate ) ;
%EXPORT_TAGS = %IO::Uncompress::Base::DEFLATE_CONSTANTS ;
push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
Exporter::export_ok_tags('all');
# TODO - allow the user to pick a set of the three formats to allow
# or just assume want to auto-detect any of the three formats.
sub new
{
my $class = shift ;
my $obj = createSelfTiedObject($class, \$AnyInflateError);
$obj->_create(undef, 0, @_);
}
sub anyinflate
{
my $obj = createSelfTiedObject(undef, \$AnyInflateError);
return $obj->_inf(@_) ;
}
sub getExtraParams
{
use IO::Compress::Base::Common 2.021 qw(:Parse);
return ( 'RawInflate' => [1, 1, Parse_boolean, 0] ) ;
}
sub ckParams
{
my $self = shift ;
my $got = shift ;
# any always needs both crc32 and adler32
$got->value('CRC32' => 1);
$got->value('ADLER32' => 1);
return 1;
}
sub mkUncomp
{
my $self = shift ;
my $got = shift ;
my ($obj, $errstr, $errno) = IO::Uncompress::Adapter::Inflate::mkUncompObject();
return $self->saveErrorString(undef, $errstr, $errno)
if ! defined $obj;
*$self->{Uncomp} = $obj;
my @possible = qw( Inflate Gunzip Unzip );
unshift @possible, 'RawInflate'
if 1 || $got->value('RawInflate');
my $magic = $self->ckMagic( @possible );
if ($magic) {
*$self->{Info} = $self->readHeader($magic)
or return undef ;
return 1;
}
return 0 ;
}
sub ckMagic
{
my $self = shift;
my @names = @_ ;
my $keep = ref $self ;
for my $class ( map { "IO::Uncompress::$_" } @names)
{
bless $self => $class;
my $magic = $self->ckMagic();
if ($magic)
{
#bless $self => $class;
return $magic ;
}
$self->pushBack(*$self->{HeaderPending}) ;
*$self->{HeaderPending} = '' ;
}
bless $self => $keep;
return undef;
}
1 ;
__END__
=head1 NAME
IO::Uncompress::AnyInflate - Uncompress zlib-based (zip, gzip) file/buffer
=head1 SYNOPSIS
use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
my $status = anyinflate $input => $output [,OPTS]
or die "anyinflate failed: $AnyInflateError\n";
my $z = new IO::Uncompress::AnyInflate $input [OPTS]
or die "anyinflate failed: $AnyInflateError\n";
$status = $z->read($buffer)
$status = $z->read($buffer, $length)
$status = $z->read($buffer, $length, $offset)
$line = $z->getline()
$char = $z->getc()
$char = $z->ungetc()
$char = $z->opened()
$status = $z->inflateSync()
$data = $z->trailingData()
$status = $z->nextStream()
$data = $z->getHeaderInfo()
$z->tell()
$z->seek($position, $whence)
$z->binmode()
$z->fileno()
$z->eof()
$z->close()
$AnyInflateError ;
# IO::File mode
<$z>
read($z, $buffer);
read($z, $buffer, $length);
read($z, $buffer, $length, $offset);
tell($z)
seek($z, $position, $whence)
binmode($z)
fileno($z)
eof($z)
close($z)
=head1 DESCRIPTION
This module provides a Perl interface that allows the reading of
files/buffers that have been compressed in a number of formats that use the
zlib compression library.
The formats supported are
=over 5
=item RFC 1950
=item RFC 1951 (optionally)
=item gzip (RFC 1952)
=item zip
=back
The module will auto-detect which, if any, of the supported
compression formats is being used.
=head1 Functional Interface
A top-level function, C, is provided to carry out
"one-shot" uncompression between buffers and/or files. For finer
control over the uncompression process, see the L"OO Interface">
section.
use IO::Uncompress::AnyInflate qw(anyinflate $AnyInflateError) ;
anyinflate $input => $output [,OPTS]
or die "anyinflate failed: $AnyInflateError\n";
The functional interface needs Perl5.005 or better.
=head2 anyinflate $input => $output [, OPTS]
C expects at least two parameters, C<$input> and C<$output>.
=head3 The C<$input> parameter
The parameter, C<$input>, is used to define the source of
the compressed data.
It can take one of the following forms:
=over 5
=item A filename
If the C<$input> parameter is a simple scalar, it is assumed to be a
filename. This file will be opened for reading and the input data
will be read from it.
=item A filehandle
If the C<$input> parameter is a filehandle, the input data will be
read from it.
The string '-' can be used as an alias for standard input.
=item A scalar reference
If C<$input> is a scalar reference, the input data will be read
from C<$$input>.
=item An array reference
If C<$input> is an array reference, each element in the array must be a
filename.
The input data will be read from each file in turn.
The complete array will be walked to ensure that it only
contains valid filenames before any data is uncompressed.
=item An Input FileGlob string
If C<$input> is a string that is delimited by the characters "<" and ">"
C will assume that it is an I. The
input is the list of files that match the fileglob.
If the fileglob does not match any files ...
See L for more details.
=back
If the C<$input> parameter is any other type, C will be returned.
=head3 The C<$output> parameter
The parameter C<$output> is used to control the destination of the
uncompressed data. This parameter can take one of these forms.
=over 5
=item A filename
If the C<$output> parameter is a simple scalar, it is assumed to be a
filename. This file will be opened for writing and the uncompressed
data will be written to it.
=item A filehandle
If the C<$output> parameter is a filehandle, the uncompressed data
will be written to it.
The string '-' can be used as an alias for standard output.
=item A scalar reference
If C<$output> is a scalar reference, the uncompressed data will be
stored in C<$$output>.
=item An Array Reference
If C<$output> is an array reference, the uncompressed data will be
pushed onto the array.
=item An Output FileGlob
If C<$output> is a string that is delimited by the characters "<" and ">"
C will assume that it is an I