<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package IO::Compress::Base::Common;

use strict ;
use warnings;
use bytes;

use Carp;
use Scalar::Util qw(blessed readonly);
use File::GlobMapper;

require Exporter;
our ($VERSION, @ISA, @EXPORT, %EXPORT_TAGS, $HAS_ENCODE);
@ISA = qw(Exporter);
$VERSION = '2.048';

@EXPORT = qw( isaFilehandle isaFilename isaScalar
              whatIsInput whatIsOutput 
              isaFileGlobString cleanFileGlobString oneTarget
              setBinModeInput setBinModeOutput
              ckInOutParams 
              createSelfTiedObject
              getEncoding

              isGeMax32

              MAX32

              WANT_CODE
              WANT_EXT
              WANT_UNDEF
              WANT_HASH

              STATUS_OK
              STATUS_ENDSTREAM
              STATUS_EOF
              STATUS_ERROR
          );  

%EXPORT_TAGS = ( Status =&gt; [qw( STATUS_OK
                                 STATUS_ENDSTREAM
                                 STATUS_EOF
                                 STATUS_ERROR
                           )]);

                       
use constant STATUS_OK        =&gt; 0;
use constant STATUS_ENDSTREAM =&gt; 1;
use constant STATUS_EOF       =&gt; 2;
use constant STATUS_ERROR     =&gt; -1;
use constant MAX16            =&gt; 0xFFFF ;  
use constant MAX32            =&gt; 0xFFFFFFFF ;  
use constant MAX32cmp         =&gt; 0xFFFFFFFF + 1 - 1; # for 5.6.x on 32-bit need to force an non-IV value 
          

sub isGeMax32
{
    return $_[0] &gt;= MAX32cmp ;
}

sub hasEncode()
{
    if (! defined $HAS_ENCODE) {
        eval
        {
            require Encode;
            Encode-&gt;import();
        };

        $HAS_ENCODE = $@ ? 0 : 1 ;
    }

    return $HAS_ENCODE;
}

sub getEncoding($$$)
{
    my $obj = shift;
    my $class = shift ;
    my $want_encoding = shift ;

    $obj-&gt;croakError("$class: Encode module needed to use -Encode")
        if ! hasEncode();

    my $encoding = Encode::find_encoding($want_encoding);

    $obj-&gt;croakError("$class: Encoding '$want_encoding' is not available")
       if ! $encoding;

    return $encoding;
}

our ($needBinmode);
$needBinmode = ($^O eq 'MSWin32' || 
                    ($] &gt;= 5.006 &amp;&amp; eval ' ${^UNICODE} || ${^UTF8LOCALE} '))
                    ? 1 : 1 ;

sub setBinModeInput($)
{
    my $handle = shift ;

    binmode $handle 
        if  $needBinmode;
}

sub setBinModeOutput($)
{
    my $handle = shift ;

    binmode $handle 
        if  $needBinmode;
}

sub isaFilehandle($)
{
    use utf8; # Pragma needed to keep Perl 5.6.0 happy
    return (defined $_[0] and 
             (UNIVERSAL::isa($_[0],'GLOB') or 
              UNIVERSAL::isa($_[0],'IO::Handle') or
              UNIVERSAL::isa(\$_[0],'GLOB')) 
          )
}

sub isaScalar
{
    return ( defined($_[0]) and ref($_[0]) eq 'SCALAR' and defined ${ $_[0] } ) ;
}

sub isaFilename($)
{
    return (defined $_[0] and 
           ! ref $_[0]    and 
           UNIVERSAL::isa(\$_[0], 'SCALAR'));
}

sub isaFileGlobString
{
    return defined $_[0] &amp;&amp; $_[0] =~ /^&lt;.*&gt;$/;
}

sub cleanFileGlobString
{
    my $string = shift ;

    $string =~ s/^\s*&lt;\s*(.*)\s*&gt;\s*$/$1/;

    return $string;
}

use constant WANT_CODE  =&gt; 1 ;
use constant WANT_EXT   =&gt; 2 ;
use constant WANT_UNDEF =&gt; 4 ;
#use constant WANT_HASH  =&gt; 8 ;
use constant WANT_HASH  =&gt; 0 ;

sub whatIsInput($;$)
{
    my $got = whatIs(@_);
    
    if (defined $got &amp;&amp; $got eq 'filename' &amp;&amp; defined $_[0] &amp;&amp; $_[0] eq '-')
    {
        #use IO::File;
        $got = 'handle';
        $_[0] = *STDIN;
        #$_[0] = new IO::File("&lt;-");
    }

    return $got;
}

sub whatIsOutput($;$)
{
    my $got = whatIs(@_);
    
    if (defined $got &amp;&amp; $got eq 'filename' &amp;&amp; defined $_[0] &amp;&amp; $_[0] eq '-')
    {
        $got = 'handle';
        $_[0] = *STDOUT;
        #$_[0] = new IO::File("&gt;-");
    }
    
    return $got;
}

sub whatIs ($;$)
{
    return 'handle' if isaFilehandle($_[0]);

    my $wantCode = defined $_[1] &amp;&amp; $_[1] &amp; WANT_CODE ;
    my $extended = defined $_[1] &amp;&amp; $_[1] &amp; WANT_EXT ;
    my $undef    = defined $_[1] &amp;&amp; $_[1] &amp; WANT_UNDEF ;
    my $hash     = defined $_[1] &amp;&amp; $_[1] &amp; WANT_HASH ;

    return 'undef'  if ! defined $_[0] &amp;&amp; $undef ;

    if (ref $_[0]) {
        return ''       if blessed($_[0]); # is an object
        #return ''       if UNIVERSAL::isa($_[0], 'UNIVERSAL'); # is an object
        return 'buffer' if UNIVERSAL::isa($_[0], 'SCALAR');
        return 'array'  if UNIVERSAL::isa($_[0], 'ARRAY')  &amp;&amp; $extended ;
        return 'hash'   if UNIVERSAL::isa($_[0], 'HASH')   &amp;&amp; $hash ;
        return 'code'   if UNIVERSAL::isa($_[0], 'CODE')   &amp;&amp; $wantCode ;
        return '';
    }

    return 'fileglob' if $extended &amp;&amp; isaFileGlobString($_[0]);
    return 'filename';
}

sub oneTarget
{
    return $_[0] =~ /^(code|handle|buffer|filename)$/;
}

sub IO::Compress::Base::Validator::new
{
    my $class = shift ;

    my $Class = shift ;
    my $error_ref = shift ;
    my $reportClass = shift ;

    my %data = (Class       =&gt; $Class, 
                Error       =&gt; $error_ref,
                reportClass =&gt; $reportClass, 
               ) ;

    my $obj = bless \%data, $class ;

    local $Carp::CarpLevel = 1;

    my $inType    = $data{inType}    = whatIsInput($_[0], WANT_EXT|WANT_HASH);
    my $outType   = $data{outType}   = whatIsOutput($_[1], WANT_EXT|WANT_HASH);

    my $oneInput  = $data{oneInput}  = oneTarget($inType);
    my $oneOutput = $data{oneOutput} = oneTarget($outType);

    if (! $inType)
    {
        $obj-&gt;croakError("$reportClass: illegal input parameter") ;
        #return undef ;
    }    

#    if ($inType eq 'hash')
#    {
#        $obj-&gt;{Hash} = 1 ;
#        $obj-&gt;{oneInput} = 1 ;
#        return $obj-&gt;validateHash($_[0]);
#    }

    if (! $outType)
    {
        $obj-&gt;croakError("$reportClass: illegal output parameter") ;
        #return undef ;
    }    


    if ($inType ne 'fileglob' &amp;&amp; $outType eq 'fileglob')
    {
        $obj-&gt;croakError("Need input fileglob for outout fileglob");
    }    

#    if ($inType ne 'fileglob' &amp;&amp; $outType eq 'hash' &amp;&amp; $inType ne 'filename' )
#    {
#        $obj-&gt;croakError("input must ne filename or fileglob when output is a hash");
#    }    

    if ($inType eq 'fileglob' &amp;&amp; $outType eq 'fileglob')
    {
        $data{GlobMap} = 1 ;
        $data{inType} = $data{outType} = 'filename';
        my $mapper = new File::GlobMapper($_[0], $_[1]);
        if ( ! $mapper )
        {
            return $obj-&gt;saveErrorString($File::GlobMapper::Error) ;
        }
        $data{Pairs} = $mapper-&gt;getFileMap();

        return $obj;
    }
    
    $obj-&gt;croakError("$reportClass: input and output $inType are identical")
        if $inType eq $outType &amp;&amp; $_[0] eq $_[1] &amp;&amp; $_[0] ne '-' ;

    if ($inType eq 'fileglob') # &amp;&amp; $outType ne 'fileglob'
    {
        my $glob = cleanFileGlobString($_[0]);
        my @inputs = glob($glob);

        if (@inputs == 0)
        {
            # TODO -- legal or die?
            die "globmap matched zero file -- legal or die???" ;
        }
        elsif (@inputs == 1)
        {
            $obj-&gt;validateInputFilenames($inputs[0])
                or return undef;
            $_[0] = $inputs[0]  ;
            $data{inType} = 'filename' ;
            $data{oneInput} = 1;
        }
        else
        {
            $obj-&gt;validateInputFilenames(@inputs)
                or return undef;
            $_[0] = [ @inputs ] ;
            $data{inType} = 'filenames' ;
        }
    }
    elsif ($inType eq 'filename')
    {
        $obj-&gt;validateInputFilenames($_[0])
            or return undef;
    }
    elsif ($inType eq 'array')
    {
        $data{inType} = 'filenames' ;
        $obj-&gt;validateInputArray($_[0])
            or return undef ;
    }

    return $obj-&gt;saveErrorString("$reportClass: output buffer is read-only")
        if $outType eq 'buffer' &amp;&amp; readonly(${ $_[1] });

    if ($outType eq 'filename' )
    {
        $obj-&gt;croakError("$reportClass: output filename is undef or null string")
            if ! defined $_[1] || $_[1] eq ''  ;

        if (-e $_[1])
        {
            if (-d _ )
            {
                return $obj-&gt;saveErrorString("output file '$_[1]' is a directory");
            }
        }
    }
    
    return $obj ;
}

sub IO::Compress::Base::Validator::saveErrorString
{
    my $self   = shift ;
    ${ $self-&gt;{Error} } = shift ;
    return undef;
    
}

sub IO::Compress::Base::Validator::croakError
{
    my $self   = shift ;
    $self-&gt;saveErrorString($_[0]);
    croak $_[0];
}



sub IO::Compress::Base::Validator::validateInputFilenames
{
    my $self = shift ;

    foreach my $filename (@_)
    {
        $self-&gt;croakError("$self-&gt;{reportClass}: input filename is undef or null string")
            if ! defined $filename || $filename eq ''  ;

        next if $filename eq '-';

        if (! -e $filename )
        {
            return $self-&gt;saveErrorString("input file '$filename' does not exist");
        }

        if (-d _ )
        {
            return $self-&gt;saveErrorString("input file '$filename' is a directory");
        }

        if (! -r _ )
        {
            return $self-&gt;saveErrorString("cannot open file '$filename': $!");
        }
    }

    return 1 ;
}

sub IO::Compress::Base::Validator::validateInputArray
{
    my $self = shift ;

    if ( @{ $_[0] } == 0 )
    {
        return $self-&gt;saveErrorString("empty array reference") ;
    }    

    foreach my $element ( @{ $_[0] } )
    {
        my $inType  = whatIsInput($element);
    
        if (! $inType)
        {
            $self-&gt;croakError("unknown input parameter") ;
        }    
        elsif($inType eq 'filename')
        {
            $self-&gt;validateInputFilenames($element)
                or return undef ;
        }
        else
        {
            $self-&gt;croakError("not a filename") ;
        }
    }

    return 1 ;
}

#sub IO::Compress::Base::Validator::validateHash
#{
#    my $self = shift ;
#    my $href = shift ;
#
#    while (my($k, $v) = each %$href)
#    {
#        my $ktype = whatIsInput($k);
#        my $vtype = whatIsOutput($v, WANT_EXT|WANT_UNDEF) ;
#
#        if ($ktype ne 'filename')
#        {
#            return $self-&gt;saveErrorString("hash key not filename") ;
#        }    
#
#        my %valid = map { $_ =&gt; 1 } qw(filename buffer array undef handle) ;
#        if (! $valid{$vtype})
#        {
#            return $self-&gt;saveErrorString("hash value not ok") ;
#        }    
#    }
#
#    return $self ;
#}

sub createSelfTiedObject
{
    my $class = shift || (caller)[0] ;
    my $error_ref = shift ;

    my $obj = bless Symbol::gensym(), ref($class) || $class;
    tie *$obj, $obj if $] &gt;= 5.005;
    *$obj-&gt;{Closed} = 1 ;
    $$error_ref = '';
    *$obj-&gt;{Error} = $error_ref ;
    my $errno = 0 ;
    *$obj-&gt;{ErrorNo} = \$errno ;

    return $obj;
}



#package Parse::Parameters ;
#
#
#require Exporter;
#our ($VERSION, @ISA, @EXPORT);
#$VERSION = '2.000_08';
#@ISA = qw(Exporter);

$EXPORT_TAGS{Parse} = [qw( ParseParameters 
                           Parse_any Parse_unsigned Parse_signed 
                           Parse_boolean Parse_string
                           Parse_code
                           Parse_multiple Parse_writable_scalar
                         )
                      ];              

push @EXPORT, @{ $EXPORT_TAGS{Parse} } ;

use constant Parse_any      =&gt; 0x01;
use constant Parse_unsigned =&gt; 0x02;
use constant Parse_signed   =&gt; 0x04;
use constant Parse_boolean  =&gt; 0x08;
use constant Parse_string   =&gt; 0x10;
use constant Parse_code     =&gt; 0x20;

#use constant Parse_store_ref        =&gt; 0x100 ;
use constant Parse_multiple         =&gt; 0x100 ;
use constant Parse_writable         =&gt; 0x200 ;
use constant Parse_writable_scalar  =&gt; 0x400 | Parse_writable ;

use constant OFF_PARSED     =&gt; 0 ;
use constant OFF_TYPE       =&gt; 1 ;
use constant OFF_DEFAULT    =&gt; 2 ;
use constant OFF_FIXED      =&gt; 3 ;
use constant OFF_FIRST_ONLY =&gt; 4 ;
use constant OFF_STICKY     =&gt; 5 ;



sub ParseParameters
{
    my $level = shift || 0 ; 

    my $sub = (caller($level + 1))[3] ;
    local $Carp::CarpLevel = 1 ;
    
    return $_[1]
        if @_ == 2 &amp;&amp; defined $_[1] &amp;&amp; UNIVERSAL::isa($_[1], "IO::Compress::Base::Parameters");
    
    my $p = new IO::Compress::Base::Parameters() ;            
    $p-&gt;parse(@_)
        or croak "$sub: $p-&gt;{Error}" ;

    return $p;
}

#package IO::Compress::Base::Parameters;

use strict;

use warnings;
use Carp;

sub IO::Compress::Base::Parameters::new
{
    my $class = shift ;

    my $obj = { Error =&gt; '',
                Got   =&gt; {},
              } ;

    #return bless $obj, ref($class) || $class || __PACKAGE__ ;
    return bless $obj, 'IO::Compress::Base::Parameters' ;
}

sub IO::Compress::Base::Parameters::setError
{
    my $self = shift ;
    my $error = shift ;
    my $retval = @_ ? shift : undef ;

    $self-&gt;{Error} = $error ;
    return $retval;
}
          
#sub getError
#{
#    my $self = shift ;
#    return $self-&gt;{Error} ;
#}
          
sub IO::Compress::Base::Parameters::parse
{
    my $self = shift ;

    my $default = shift ;

    my $got = $self-&gt;{Got} ;
    my $firstTime = keys %{ $got } == 0 ;
    my $other;

    my (@Bad) ;
    my @entered = () ;

    # Allow the options to be passed as a hash reference or
    # as the complete hash.
    if (@_ == 0) {
        @entered = () ;
    }
    elsif (@_ == 1) {
        my $href = $_[0] ;
    
        return $self-&gt;setError("Expected even number of parameters, got 1")
            if ! defined $href or ! ref $href or ref $href ne "HASH" ;
 
        foreach my $key (keys %$href) {
            push @entered, $key ;
            push @entered, \$href-&gt;{$key} ;
        }
    }
    else {
        my $count = @_;
        return $self-&gt;setError("Expected even number of parameters, got $count")
            if $count % 2 != 0 ;
        
        for my $i (0.. $count / 2 - 1) {
            if ($_[2 * $i] eq '__xxx__') {
                $other = $_[2 * $i + 1] ;
            }
            else {
                push @entered, $_[2 * $i] ;
                push @entered, \$_[2 * $i + 1] ;
            }
        }
    }


    while (my ($key, $v) = each %$default)
    {
        croak "need 4 params [@$v]"
            if @$v != 4 ;

        my ($first_only, $sticky, $type, $value) = @$v ;
        my $x ;
        $self-&gt;_checkType($key, \$value, $type, 0, \$x) 
            or return undef ;

        $key = lc $key;

        if ($firstTime || ! $sticky) {
            $x = []
                if $type &amp; Parse_multiple;

            $got-&gt;{$key} = [0, $type, $value, $x, $first_only, $sticky] ;
        }

        $got-&gt;{$key}[OFF_PARSED] = 0 ;
    }

    my %parsed = ();
    
    if ($other) 
    {
        for my $key (keys %$default)  
        {
            my $canonkey = lc $key;
            if ($other-&gt;parsed($canonkey))
            {
                my $value = $other-&gt;value($canonkey);
#print "SET '$canonkey' to $value [$$value]\n";
                ++ $parsed{$canonkey};
                $got-&gt;{$canonkey}[OFF_PARSED]  = 1;
                $got-&gt;{$canonkey}[OFF_DEFAULT] = $value;
                $got-&gt;{$canonkey}[OFF_FIXED]   = $value;
            }
        }
    }
    
    for my $i (0.. @entered / 2 - 1) {
        my $key = $entered[2* $i] ;
        my $value = $entered[2* $i+1] ;

        #print "Key [$key] Value [$value]" ;
        #print defined $$value ? "[$$value]\n" : "[undef]\n";

        $key =~ s/^-// ;
        my $canonkey = lc $key;
 
        if ($got-&gt;{$canonkey} &amp;&amp; ($firstTime ||
                                  ! $got-&gt;{$canonkey}[OFF_FIRST_ONLY]  ))
        {
            my $type = $got-&gt;{$canonkey}[OFF_TYPE] ;
            my $parsed = $parsed{$canonkey};
            ++ $parsed{$canonkey};

            return $self-&gt;setError("Muliple instances of '$key' found") 
                if $parsed &amp;&amp; ($type &amp; Parse_multiple) == 0 ;

            my $s ;
            $self-&gt;_checkType($key, $value, $type, 1, \$s)
                or return undef ;

            $value = $$value ;
            if ($type &amp; Parse_multiple) {
                $got-&gt;{$canonkey}[OFF_PARSED] = 1;
                push @{ $got-&gt;{$canonkey}[OFF_FIXED] }, $s ;
            }
            else {
                $got-&gt;{$canonkey} = [1, $type, $value, $s] ;
            }
        }
        else
          { push (@Bad, $key) }
    }
 
    if (@Bad) {
        my ($bad) = join(", ", @Bad) ;
        return $self-&gt;setError("unknown key value(s) $bad") ;
    }

    return 1;
}

sub IO::Compress::Base::Parameters::_checkType
{
    my $self = shift ;

    my $key   = shift ;
    my $value = shift ;
    my $type  = shift ;
    my $validate  = shift ;
    my $output  = shift;

    #local $Carp::CarpLevel = $level ;
    #print "PARSE $type $key $value $validate $sub\n" ;

    if ($type &amp; Parse_writable_scalar)
    {
        return $self-&gt;setError("Parameter '$key' not writable")
            if $validate &amp;&amp;  readonly $$value ;

        if (ref $$value) 
        {
            return $self-&gt;setError("Parameter '$key' not a scalar reference")
                if $validate &amp;&amp;  ref $$value ne 'SCALAR' ;

            $$output = $$value ;
        }
        else  
        {
            return $self-&gt;setError("Parameter '$key' not a scalar")
                if $validate &amp;&amp;  ref $value ne 'SCALAR' ;

            $$output = $value ;
        }

        return 1;
    }

#    if ($type &amp; Parse_store_ref)
#    {
#        #$value = $$value
#        #    if ref ${ $value } ;
#
#        $$output = $value ;
#        return 1;
#    }

    $value = $$value ;

    if ($type &amp; Parse_any)
    {
        $$output = $value ;
        return 1;
    }
    elsif ($type &amp; Parse_unsigned)
    {
        return $self-&gt;setError("Parameter '$key' must be an unsigned int, got 'undef'")
            if $validate &amp;&amp; ! defined $value ;
        return $self-&gt;setError("Parameter '$key' must be an unsigned int, got '$value'")
            if $validate &amp;&amp; $value !~ /^\d+$/;

        $$output = defined $value ? $value : 0 ;    
        return 1;
    }
    elsif ($type &amp; Parse_signed)
    {
        return $self-&gt;setError("Parameter '$key' must be a signed int, got 'undef'")
            if $validate &amp;&amp; ! defined $value ;
        return $self-&gt;setError("Parameter '$key' must be a signed int, got '$value'")
            if $validate &amp;&amp; $value !~ /^-?\d+$/;

        $$output = defined $value ? $value : 0 ;    
        return 1 ;
    }
    elsif ($type &amp; Parse_boolean)
    {
        return $self-&gt;setError("Parameter '$key' must be an int, got '$value'")
            if $validate &amp;&amp; defined $value &amp;&amp; $value !~ /^\d*$/;
        $$output =  defined $value ? $value != 0 : 0 ;    
        return 1;
    }
    elsif ($type &amp; Parse_code)
    {
        return $self-&gt;setError("Parameter '$key' must be a code reference, got '$value'")
            if $validate &amp;&amp; (! defined $value || ref $value ne 'CODE') ;
        $$output = defined $value ? $value : "" ;    
        return 1;
    }
    elsif ($type &amp; Parse_string)
    {
        $$output = defined $value ? $value : "" ;    
        return 1;
    }

    $$output = $value ;
    return 1;
}



sub IO::Compress::Base::Parameters::parsed
{
    my $self = shift ;
    my $name = shift ;

    return $self-&gt;{Got}{lc $name}[OFF_PARSED] ;
}

sub IO::Compress::Base::Parameters::value
{
    my $self = shift ;
    my $name = shift ;

    if (@_)
    {
        $self-&gt;{Got}{lc $name}[OFF_PARSED]  = 1;
        $self-&gt;{Got}{lc $name}[OFF_DEFAULT] = $_[0] ;
        $self-&gt;{Got}{lc $name}[OFF_FIXED]   = $_[0] ;
    }

    return $self-&gt;{Got}{lc $name}[OFF_FIXED] ;
}

sub IO::Compress::Base::Parameters::valueOrDefault
{
    my $self = shift ;
    my $name = shift ;
    my $default = shift ;

    my $value = $self-&gt;{Got}{lc $name}[OFF_DEFAULT] ;

    return $value if defined $value ;
    return $default ;
}

sub IO::Compress::Base::Parameters::wantValue
{
    my $self = shift ;
    my $name = shift ;

    return defined $self-&gt;{Got}{lc $name}[OFF_DEFAULT] ;

}

sub IO::Compress::Base::Parameters::clone
{
    my $self = shift ;
    my $obj = { };
    my %got ;

    while (my ($k, $v) = each %{ $self-&gt;{Got} }) {
        $got{$k} = [ @$v ];
    }

    $obj-&gt;{Error} = $self-&gt;{Error};
    $obj-&gt;{Got} = \%got ;

    return bless $obj, 'IO::Compress::Base::Parameters' ;
}

package U64;

use constant MAX32 =&gt; 0xFFFFFFFF ;
use constant HI_1 =&gt; MAX32 + 1 ;
use constant LOW   =&gt; 0 ;
use constant HIGH  =&gt; 1;

sub new
{
    my $class = shift ;

    my $high = 0 ;
    my $low  = 0 ;

    if (@_ == 2) {
        $high = shift ;
        $low  = shift ;
    }
    elsif (@_ == 1) {
        $low  = shift ;
    }

    bless [$low, $high], $class;
}

sub newUnpack_V64
{
    my $string = shift;

    my ($low, $hi) = unpack "V V", $string ;
    bless [ $low, $hi ], "U64";
}

sub newUnpack_V32
{
    my $string = shift;

    my $low = unpack "V", $string ;
    bless [ $low, 0 ], "U64";
}

sub reset
{
    my $self = shift;
    $self-&gt;[HIGH] = $self-&gt;[LOW] = 0;
}

sub clone
{
    my $self = shift;
    bless [ @$self ], ref $self ;
}

sub getHigh
{
    my $self = shift;
    return $self-&gt;[HIGH];
}

sub getLow
{
    my $self = shift;
    return $self-&gt;[LOW];
}

sub get32bit
{
    my $self = shift;
    return $self-&gt;[LOW];
}

sub get64bit
{
    my $self = shift;
    # Not using &lt;&lt; here because the result will still be
    # a 32-bit value on systems where int size is 32-bits
    return $self-&gt;[HIGH] * HI_1 + $self-&gt;[LOW];
}

sub add
{
    my $self = shift;
    my $value = shift;

    if (ref $value eq 'U64') {
        $self-&gt;[HIGH] += $value-&gt;[HIGH] ;
        $value = $value-&gt;[LOW];
    }
    elsif ($value &gt; MAX32) {      
        $self-&gt;[HIGH] += int($value / HI_1) ;
        $value = $value % HI_1;
    }
     
    my $available = MAX32 - $self-&gt;[LOW] ;
 
    if ($value &gt; $available) {
       ++ $self-&gt;[HIGH] ;
       $self-&gt;[LOW] = $value - $available - 1;
    }
    else {
       $self-&gt;[LOW] += $value ;
    }
}

sub subtract
{
    my $self = shift;
    my $value = shift;

    if (ref $value eq 'U64') {

        if ($value-&gt;[HIGH]) {
            die "bad"
                if $self-&gt;[HIGH] == 0 ||
                   $value-&gt;[HIGH] &gt; $self-&gt;[HIGH] ;

           $self-&gt;[HIGH] -= $value-&gt;[HIGH] ;
        }

        $value = $value-&gt;[LOW] ;
    }

    if ($value &gt; $self-&gt;[LOW]) {
       -- $self-&gt;[HIGH] ;
       $self-&gt;[LOW] = MAX32 - $value + $self-&gt;[LOW] + 1 ;
    }
    else {
       $self-&gt;[LOW] -= $value;
    }
}

sub equal
{
    my $self = shift;
    my $other = shift;

    return $self-&gt;[LOW]  == $other-&gt;[LOW] &amp;&amp;
           $self-&gt;[HIGH] == $other-&gt;[HIGH] ;
}

sub gt
{
    my $self = shift;
    my $other = shift;

    return $self-&gt;cmp($other) &gt; 0 ;
}

sub cmp
{
    my $self = shift;
    my $other = shift ;

    if ($self-&gt;[LOW] == $other-&gt;[LOW]) {
        return $self-&gt;[HIGH] - $other-&gt;[HIGH] ;
    }
    else {
        return $self-&gt;[LOW] - $other-&gt;[LOW] ;
    }
}
    

sub is64bit
{
    my $self = shift;
    return $self-&gt;[HIGH] &gt; 0 ;
}

sub isAlmost64bit
{
    my $self = shift;
    return $self-&gt;[HIGH] &gt; 0 ||  $self-&gt;[LOW] == MAX32 ;
}

sub getPacked_V64
{
    my $self = shift;

    return pack "V V", @$self ;
}

sub getPacked_V32
{
    my $self = shift;

    return pack "V", $self-&gt;[LOW] ;
}

sub pack_V64
{
    my $low  = shift;

    return pack "V V", $low, 0;
}


sub full32 
{
    return $_[0] == MAX32 ;
}

sub Value_VV64
{
    my $buffer = shift;

    my ($lo, $hi) = unpack ("V V" , $buffer);
    no warnings 'uninitialized';
    return $hi * HI_1 + $lo;
}


package IO::Compress::Base::Common;

1;
</pre></body></html>