use strict;
use warnings;
+
+use Compress::Zlib::Common qw(createSelfTiedObject);
+
+use UncompressPlugin::Inflate ();
+#use UncompressPlugin::Bunzip2 ();
+
+
+#use IO::Uncompress::Base ;
use IO::Uncompress::Gunzip ;
+use IO::Uncompress::Inflate ;
+use IO::Uncompress::RawInflate ;
+use IO::Uncompress::Unzip ;
+#use IO::Uncompress::Bunzip2 ;
+#use IO::Uncompress::UnLzop ;
require Exporter ;
our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, $AnyInflateError);
-$VERSION = '2.000_05';
+$VERSION = '2.000_07';
$AnyInflateError = '';
-@ISA = qw(Exporter IO::BaseInflate);
+@ISA = qw( Exporter IO::Uncompress::Base );
@EXPORT_OK = qw( $AnyInflateError anyinflate ) ;
-%EXPORT_TAGS = %IO::BaseInflate::EXPORT_TAGS ;
+%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 $pkg = shift ;
- return IO::BaseInflate::new($pkg, 'any', undef, \$AnyInflateError, 0, @_);
+ my $class = shift ;
+ my $obj = createSelfTiedObject($class, \$AnyInflateError);
+ $obj->_create(undef, 0, @_);
}
sub anyinflate
{
- return IO::BaseInflate::_inf(__PACKAGE__, 'any', \$AnyInflateError, @_) ;
+ my $obj = createSelfTiedObject(undef, \$AnyInflateError);
+ return $obj->_inf(@_) ;
+}
+
+sub getExtraParams
+{
+ return ();
+}
+
+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 $class = shift ;
+ my $got = shift ;
+
+ my ($obj, $errstr, $errno) = UncompressPlugin::Inflate::mkUncompObject();
+
+ return $self->saveErrorString(undef, $errstr, $errno)
+ if ! defined $obj;
+
+ *$self->{Uncomp} = $obj;
+
+ my $magic = $self->ckMagic( qw( RawInflate Inflate Gunzip Unzip ) );
+
+ 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 ;
-This module provides a Perl interface that allows the reading of files/buffers
-that conform to RFC's 1950, 1951 and 1952.
+This module provides a Perl interface that allows the reading of
+files/buffers that conform to RFC's 1950, 1951 and 1952.
-The module will auto-detect which, if any, of the three supported compression
-formats is being used.
+The module will auto-detect which, if any, of the three supported
+compression formats is being used.
=head1 Functional Interface
-A top-level function, C<anyinflate>, 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.
+A top-level function, C<anyinflate>, 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";
- anyinflate \%hash [,OPTS]
- or die "anyinflate failed: $AnyInflateError\n";
+
The functional interface needs Perl5.005 or better.
=head2 anyinflate $input => $output [, OPTS]
-If the first parameter is not a hash reference C<anyinflate> expects
-at least two parameters, C<$input> and C<$output>.
+
+C<anyinflate> expects at least two parameters, C<$input> and C<$output>.
=head3 The C<$input> parameter
=item An array reference
-If C<$input> is an array reference, the input data will be read from each
-element of the array in turn. The action taken by C<anyinflate> with
-each element of the array will depend on the type of data stored
-in it. You can mix and match any of the types defined in this list,
-excluding other array or hash references.
+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 data types before any data is uncompressed.
+contains valid filenames before any data is uncompressed.
+
+
=item An Input FileGlob string
=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.
+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.
+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 A Hash Reference
-
-If C<$output> is a hash reference, the uncompressed data will be written
-to C<$output{$input}> as a scalar reference.
+If C<$output> is a scalar reference, the uncompressed data will be
+stored in C<$$output>.
-When C<$output> is a hash reference, C<$input> must be either a filename or
-list of filenames. Anything else is an error.
=item An Array Reference
-If C<$output> is an array reference, the uncompressed data will be pushed
-onto the array.
+If C<$output> is an array reference, the uncompressed data will be
+pushed onto the array.
=item An Output FileGlob
If the C<$output> parameter is any other type, C<undef> will be returned.
-=head2 anyinflate \%hash [, OPTS]
-If the first parameter is a hash reference, C<\%hash>, this will be used to
-define both the source of compressed data and to control where the
-uncompressed data is output. Each key/value pair in the hash defines a
-mapping between an input filename, stored in the key, and an output
-file/buffer, stored in the value. Although the input can only be a filename,
-there is more flexibility to control the destination of the uncompressed
-data. This is determined by the type of the value. Valid types are
-
-=over 5
-
-=item undef
-
-If the value is C<undef> the uncompressed data will be written to the
-value as a scalar reference.
-
-=item A filename
-
-If the value 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 value 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 the value is a scalar reference, the uncompressed data will be stored
-in the buffer that is referenced by the scalar.
-
-
-=item A Hash Reference
-
-If the value is a hash reference, the uncompressed data will be written
-to C<$hash{$input}> as a scalar reference.
-
-=item An Array Reference
-
-If C<$output> is an array reference, the uncompressed data will be pushed
-onto the array.
-
-=back
-
-Any other type is a error.
=head2 Notes
When C<$input> maps to multiple files/buffers and C<$output> is a single
-file/buffer the uncompressed input files/buffers will all be stored in
-C<$output> as a single uncompressed stream.
+file/buffer the uncompressed input files/buffers will all be stored
+in C<$output> as a single uncompressed stream.
=item AutoClose =E<gt> 0|1
-This option applies to any input or output data streams to C<anyinflate>
-that are filehandles.
+This option applies to any input or output data streams to
+C<anyinflate> that are filehandles.
If C<AutoClose> is specified, and the value is true, it will result in all
input and/or output filehandles being closed once C<anyinflate> has
+=item BinModeOut =E<gt> 0|1
+
+When writing to a file or filehandle, set C<binmode> before writing to the
+file.
+
+Defaults to 0.
+
+
+
+
+
=item -Append =E<gt> 0|1
TODO
+=item -MultiStream =E<gt> 0|1
+
+Creates a new stream after each file.
+
+Defaults to 1.
+
=back
Returns an C<IO::Uncompress::AnyInflate> object on success and undef on failure.
The variable C<$AnyInflateError> will contain an error message on failure.
-If you are running Perl 5.005 or better the object, C<$z>, returned from
-IO::Uncompress::AnyInflate can be used exactly like an L<IO::File|IO::File> filehandle.
-This means that all normal input file operations can be carried out with C<$z>.
-For example, to read a line from a compressed file/buffer you can use either
-of these forms
+If you are running Perl 5.005 or better the object, C<$z>, returned from
+IO::Uncompress::AnyInflate can be used exactly like an L<IO::File|IO::File> filehandle.
+This means that all normal input file operations can be carried out with
+C<$z>. For example, to read a line from a compressed file/buffer you can
+use either of these forms
$line = $z->getline();
$line = <$z>;
This option can be useful when the compressed data is embedded in another
file/data structure and it is not possible to work out where the compressed
-data begins without having to read the first few bytes. If this is the case,
-the uncompression can be I<primed> with these bytes using this option.
+data begins without having to read the first few bytes. If this is the
+case, the uncompression can be I<primed> with these bytes using this
+option.
=item -Transparent =E<gt> 0|1
=item -BlockSize =E<gt> $num
-When reading the compressed input data, IO::Uncompress::AnyInflate will read it in blocks
-of C<$num> bytes.
+When reading the compressed input data, IO::Uncompress::AnyInflate will read it in
+blocks of C<$num> bytes.
This option defaults to 4096.
=item -InputLength =E<gt> $size
-When present this option will limit the number of compressed bytes read from
-the input file/buffer to C<$size>. This option can be used in the situation
-where there is useful data directly after the compressed data stream and you
-know beforehand the exact length of the compressed data stream.
+When present this option will limit the number of compressed bytes read
+from the input file/buffer to C<$size>. This option can be used in the
+situation where there is useful data directly after the compressed data
+stream and you know beforehand the exact length of the compressed data
+stream.
-This option is mostly used when reading from a filehandle, in which case the
-file pointer will be left pointing to the first byte directly after the
+This option is mostly used when reading from a filehandle, in which case
+the file pointer will be left pointing to the first byte directly after the
compressed data stream.
This option controls what the C<read> method does with uncompressed data.
-If set to 1, all uncompressed data will be appended to the output parameter of
-the C<read> method.
+If set to 1, all uncompressed data will be appended to the output parameter
+of the C<read> method.
-If set to 0, the contents of the output parameter of the C<read> method will be
-overwritten by the uncompressed data.
+If set to 0, the contents of the output parameter of the C<read> method
+will be overwritten by the uncompressed data.
Defaults to 0.
This option controls whether the extra checks defined below are used when
-carrying out the decompression. When Strict is on, the extra tests are carried
-out, when Strict is off they are not.
+carrying out the decompression. When Strict is on, the extra tests are
+carried out, when Strict is off they are not.
The default for this option is off.
=item 3
-If the gzip header contains a comment field (FCOMMENT) it consists solely of
-ISO 8859-1 characters plus line-feed.
+If the gzip header contains a comment field (FCOMMENT) it consists solely
+of ISO 8859-1 characters plus line-feed.
=item 4
=item 7
-The value of the ISIZE fields read must match the length of the uncompressed
-data actually read from the file.
+The value of the ISIZE fields read must match the length of the
+uncompressed data actually read from the file.
=back
Reads a block of compressed data (the size the the compressed block is
determined by the C<Buffer> option in the constructor), uncompresses it and
-writes any uncompressed data into C<$buffer>. If the C<Append> parameter is set
-in the constructor, the uncompressed data will be appended to the C<$buffer>
-parameter. Otherwise C<$buffer> will be overwritten.
+writes any uncompressed data into C<$buffer>. If the C<Append> parameter is
+set in the constructor, the uncompressed data will be appended to the
+C<$buffer> parameter. Otherwise C<$buffer> will be overwritten.
-Returns the number of uncompressed bytes written to C<$buffer>, zero if eof or
-a negative number on error.
+Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
+or a negative number on error.
=head2 read
Attempt to read C<$length> bytes of uncompressed data into C<$buffer>.
-The main difference between this form of the C<read> method and the previous
-one, is that this one will attempt to return I<exactly> C<$length> bytes. The
-only circumstances that this function will not is if end-of-file or an IO error
-is encountered.
+The main difference between this form of the C<read> method and the
+previous one, is that this one will attempt to return I<exactly> C<$length>
+bytes. The only circumstances that this function will not is if end-of-file
+or an IO error is encountered.
-Returns the number of uncompressed bytes written to C<$buffer>, zero if eof or
-a negative number on error.
+Returns the number of uncompressed bytes written to C<$buffer>, zero if eof
+or a negative number on error.
=head2 getline
Usage is
- $hdr = $z->getHeaderInfo()
-
-TODO
-
-
-
-
+ $hdr = $z->getHeaderInfo();
+ @hdrs = $z->getHeaderInfo();
+This method returns either a hash reference (in scalar context) or a list
+or hash references (in array context) that contains information about each
+of the header fields in the compressed data stream(s).
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2005 Paul Marquess. All rights reserved.
+Copyright (c) 2005-2006 Paul Marquess. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.