package Compress::Zlib;
require 5.004 ;
require Exporter;
use AutoLoader;
use Carp ;
use IO::Handle ;
use Scalar::Util qw(dualvar);
use IO::Compress::Base::Common 2.015 ;
use Compress::Raw::Zlib 2.015 ;
use IO::Compress::Gzip 2.015 ;
use IO::Uncompress::Gunzip 2.015 ;
use strict ;
use warnings ;
use bytes ;
our ($VERSION, $XS_VERSION, @ISA, @EXPORT, $AUTOLOAD);
$VERSION = '2.015';
$XS_VERSION = $VERSION;
$VERSION = eval $VERSION;
@ISA = qw(Exporter);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw(
deflateInit inflateInit
compress uncompress
gzopen $gzerrno
);
push @EXPORT, @Compress::Raw::Zlib::EXPORT ;
BEGIN
{
*zlib_version = \&Compress::Raw::Zlib::zlib_version;
}
sub AUTOLOAD {
my($constname);
($constname = $AUTOLOAD) =~ s/.*:://;
my ($error, $val) = Compress::Raw::Zlib::constant($constname);
Carp::croak $error if $error;
no strict 'refs';
*{$AUTOLOAD} = sub { $val };
goto &{$AUTOLOAD};
}
use constant FLAG_APPEND => 1 ;
use constant FLAG_CRC => 2 ;
use constant FLAG_ADLER => 4 ;
use constant FLAG_CONSUME_INPUT => 8 ;
our (@my_z_errmsg);
@my_z_errmsg = (
"need dictionary", # Z_NEED_DICT 2
"stream end", # Z_STREAM_END 1
"", # Z_OK 0
"file error", # Z_ERRNO (-1)
"stream error", # Z_STREAM_ERROR (-2)
"data error", # Z_DATA_ERROR (-3)
"insufficient memory", # Z_MEM_ERROR (-4)
"buffer error", # Z_BUF_ERROR (-5)
"incompatible version",# Z_VERSION_ERROR(-6)
);
sub _set_gzerr
{
my $value = shift ;
if ($value == 0) {
$Compress::Zlib::gzerrno = 0 ;
}
elsif ($value == Z_ERRNO() || $value > 2) {
$Compress::Zlib::gzerrno = $! ;
}
else {
$Compress::Zlib::gzerrno = dualvar($value+0, $my_z_errmsg[2 - $value]);
}
return $value ;
}
sub _save_gzerr
{
my $gz = shift ;
my $test_eof = shift ;
my $value = $gz->errorNo() || 0 ;
if ($test_eof) {
#my $gz = $self->[0] ;
# gzread uses Z_STREAM_END to denote a successful end
=1= |