<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 ;

require 5.006 ;

use strict ;
use warnings;

use IO::Compress::Base::Common 2.212 ;

use IO::File (); ;
use Scalar::Util ();

#use File::Glob;
#require Exporter ;
use Carp() ;
use Symbol();
#use bytes;

our (@ISA, $VERSION);
@ISA    = qw(IO::File Exporter);

$VERSION = '2.212';

#Can't locate object method "SWASHNEW" via package "utf8" (perhaps you forgot to load "utf8"?) at .../ext/Compress-Zlib/Gzip/blib/lib/Compress/Zlib/Common.pm line 16.

sub saveStatus
{
    my $self   = shift ;
    ${ *$self-&gt;{ErrorNo} } = shift() + 0 ;
    ${ *$self-&gt;{Error} } = '' ;

    return ${ *$self-&gt;{ErrorNo} } ;
}


sub saveErrorString
{
    my $self   = shift ;
    my $retval = shift ;
    ${ *$self-&gt;{Error} } = shift ;
    ${ *$self-&gt;{ErrorNo} } = shift() + 0 if @_ ;

    return $retval;
}

sub croakError
{
    my $self   = shift ;
    $self-&gt;saveErrorString(0, $_[0]);
    Carp::croak $_[0];
}

sub closeError
{
    my $self = shift ;
    my $retval = shift ;

    my $errno = *$self-&gt;{ErrorNo};
    my $error = ${ *$self-&gt;{Error} };

    $self-&gt;close();

    *$self-&gt;{ErrorNo} = $errno ;
    ${ *$self-&gt;{Error} } = $error ;

    return $retval;
}



sub error
{
    my $self   = shift ;
    return ${ *$self-&gt;{Error} } ;
}

sub errorNo
{
    my $self   = shift ;
    return ${ *$self-&gt;{ErrorNo} } ;
}


sub writeAt
{
    my $self = shift ;
    my $offset = shift;
    my $data = shift;

    if (defined *$self-&gt;{FH}) {
        my $here = tell(*$self-&gt;{FH});
        return $self-&gt;saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!)
            if $here &lt; 0 ;
        seek(*$self-&gt;{FH}, $offset, IO::Handle::SEEK_SET)
            or return $self-&gt;saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
        defined *$self-&gt;{FH}-&gt;write($data, length $data)
            or return $self-&gt;saveErrorString(undef, $!, $!) ;
        seek(*$self-&gt;{FH}, $here, IO::Handle::SEEK_SET)
            or return $self-&gt;saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;
    }
    else {
        substr(${ *$self-&gt;{Buffer} }, $offset, length($data)) = $data ;
    }

    return 1;
}

sub outputPayload
{

    my $self = shift ;
    return $self-&gt;output(@_);
}


sub output
{
    my $self = shift ;
    my $data = shift ;
    my $last = shift ;

    return 1
        if length $data == 0 &amp;&amp; ! $last ;

    if ( *$self-&gt;{FilterContainer} ) {
        *_ = \$data;
        &amp;{ *$self-&gt;{FilterContainer} }();
    }

    if (length $data) {
        if ( defined *$self-&gt;{FH} ) {
                defined *$self-&gt;{FH}-&gt;write( $data, length $data )
                or return $self-&gt;saveErrorString(0, $!, $!);
        }
        else {
                ${ *$self-&gt;{Buffer} } .= $data ;
        }
    }

    return 1;
}

sub getOneShotParams
{
    return ( 'multistream' =&gt; [IO::Compress::Base::Common::Parse_boolean,   1],
           );
}

our %PARAMS = (
            # Generic Parameters
            'autoclose' =&gt; [IO::Compress::Base::Common::Parse_boolean,   0],
            'encode'    =&gt; [IO::Compress::Base::Common::Parse_any,       undef],
            'strict'    =&gt; [IO::Compress::Base::Common::Parse_boolean,   1],
            'append'    =&gt; [IO::Compress::Base::Common::Parse_boolean,   0],
            'binmodein' =&gt; [IO::Compress::Base::Common::Parse_boolean,   0],

            'filtercontainer' =&gt; [IO::Compress::Base::Common::Parse_code,  undef],
        );

sub checkParams
{
    my $self = shift ;
    my $class = shift ;

    my $got = shift || IO::Compress::Base::Parameters::new();

    $got-&gt;parse(
        {
            %PARAMS,


            $self-&gt;getExtraParams(),
            *$self-&gt;{OneShot} ? $self-&gt;getOneShotParams()
                              : (),
        },
        @_) or $self-&gt;croakError("${class}: " . $got-&gt;getError())  ;

    return $got ;
}

sub _create
{
    my $obj = shift;
    my $got = shift;

    *$obj-&gt;{Closed} = 1 ;

    my $class = ref $obj;
    $obj-&gt;croakError("$class: Missing Output parameter")
        if ! @_ &amp;&amp; ! $got ;

    my $outValue = shift ;
    my $oneShot = 1 ;

    if (! $got)
    {
        $oneShot = 0 ;
        $got = $obj-&gt;checkParams($class, undef, @_)
            or return undef ;
    }

    my $lax = ! $got-&gt;getValue('strict') ;

    my $outType = IO::Compress::Base::Common::whatIsOutput($outValue);

    $obj-&gt;ckOutputParam($class, $outValue)
        or return undef ;

    if ($outType eq 'buffer') {
        *$obj-&gt;{Buffer} = $outValue;
    }
    else {
        my $buff = "" ;
        *$obj-&gt;{Buffer} = \$buff ;
    }

    # Merge implies Append
    my $merge = $got-&gt;getValue('merge') ;
    my $appendOutput = $got-&gt;getValue('append') || $merge ;
    *$obj-&gt;{Append} = $appendOutput;
    *$obj-&gt;{FilterContainer} = $got-&gt;getValue('filtercontainer') ;

    if ($merge)
    {
        # Switch off Merge mode if output file/buffer is empty/doesn't exist
        if (($outType eq 'buffer' &amp;&amp; length $$outValue == 0 ) ||
            ($outType ne 'buffer' &amp;&amp; (! -e $outValue || (-w _ &amp;&amp; -z _))) )
          { $merge = 0 }
    }

    # If output is a file, check that it is writable
    #no warnings;
    #if ($outType eq 'filename' &amp;&amp; -e $outValue &amp;&amp; ! -w _)
    #  { return $obj-&gt;saveErrorString(undef, "Output file '$outValue' is not writable" ) }

    $obj-&gt;ckParams($got)
        or $obj-&gt;croakError("${class}: " . $obj-&gt;error());

    if ($got-&gt;getValue('encode')) {
        my $want_encoding = $got-&gt;getValue('encode');
        *$obj-&gt;{Encoding} = IO::Compress::Base::Common::getEncoding($obj, $class, $want_encoding);
        my $x = *$obj-&gt;{Encoding};
    }
    else {
        *$obj-&gt;{Encoding} = undef;
    }

    $obj-&gt;saveStatus(STATUS_OK) ;

    my $status ;
    if (! $merge)
    {
        *$obj-&gt;{Compress} = $obj-&gt;mkComp($got)
            or return undef;

        *$obj-&gt;{UnCompSize} = U64-&gt;new;
        *$obj-&gt;{CompSize} = U64-&gt;new;

        if ( $outType eq 'buffer') {
            ${ *$obj-&gt;{Buffer} }  = ''
                unless $appendOutput ;
        }
        else {
            if ($outType eq 'handle') {
                *$obj-&gt;{FH} = $outValue ;
                setBinModeOutput(*$obj-&gt;{FH}) ;
                #$outValue-&gt;flush() ;
                *$obj-&gt;{Handle} = 1 ;
                if ($appendOutput)
                {
                    seek(*$obj-&gt;{FH}, 0, IO::Handle::SEEK_END)
                        or return $obj-&gt;saveErrorString(undef, "Cannot seek to end of output filehandle: $!", $!) ;

                }
            }
            elsif ($outType eq 'filename') {
                no warnings;
                my $mode = '&gt;' ;
                $mode = '&gt;&gt;'
                    if $appendOutput;
                *$obj-&gt;{FH} = IO::File-&gt;new( "$mode $outValue" )
                    or return $obj-&gt;saveErrorString(undef, "cannot open file '$outValue': $!", $!) ;
                *$obj-&gt;{StdIO} = ($outValue eq '-');
                setBinModeOutput(*$obj-&gt;{FH}) ;
            }
        }

        *$obj-&gt;{Header} = $obj-&gt;mkHeader($got) ;
        $obj-&gt;output( *$obj-&gt;{Header} )
            or return undef;
        $obj-&gt;beforePayload();
    }
    else
    {
        *$obj-&gt;{Compress} = $obj-&gt;createMerge($outValue, $outType)
            or return undef;
    }

    *$obj-&gt;{Closed} = 0 ;
    *$obj-&gt;{AutoClose} = $got-&gt;getValue('autoclose') ;
    *$obj-&gt;{Output} = $outValue;
    *$obj-&gt;{ClassName} = $class;
    *$obj-&gt;{Got} = $got;
    *$obj-&gt;{OneShot} = 0 ;

    return $obj ;
}

sub ckOutputParam
{
    my $self = shift ;
    my $from = shift ;
    my $outType = IO::Compress::Base::Common::whatIsOutput($_[0]);

    $self-&gt;croakError("$from: output parameter not a filename, filehandle or scalar ref")
        if ! $outType ;

    #$self-&gt;croakError("$from: output filename is undef or null string")
        #if $outType eq 'filename' &amp;&amp; (! defined $_[0] || $_[0] eq '')  ;

    $self-&gt;croakError("$from: output buffer is read-only")
        if $outType eq 'buffer' &amp;&amp; Scalar::Util::readonly(${ $_[0] });

    return 1;
}


sub _def
{
    my $obj = shift ;

    my $class= (caller)[0] ;
    my $name = (caller(1))[3] ;

    $obj-&gt;croakError("$name: expected at least 1 parameters\n")
        unless @_ &gt;= 1 ;

    my $input = shift ;
    my $haveOut = @_ ;
    my $output = shift ;

    my $x = IO::Compress::Base::Validator-&gt;new($class, *$obj-&gt;{Error}, $name, $input, $output)
        or return undef ;

    push @_, $output if $haveOut &amp;&amp; $x-&gt;{Hash};

    *$obj-&gt;{OneShot} = 1 ;

    my $got = $obj-&gt;checkParams($name, undef, @_)
        or return undef ;

    $x-&gt;{Got} = $got ;

#    if ($x-&gt;{Hash})
#    {
#        while (my($k, $v) = each %$input)
#        {
#            $v = \$input-&gt;{$k}
#                unless defined $v ;
#
#            $obj-&gt;_singleTarget($x, 1, $k, $v, @_)
#                or return undef ;
#        }
#
#        return keys %$input ;
#    }

    if ($x-&gt;{GlobMap})
    {
        $x-&gt;{oneInput} = 1 ;
        foreach my $pair (@{ $x-&gt;{Pairs} })
        {
            my ($from, $to) = @$pair ;
            $obj-&gt;_singleTarget($x, 1, $from, $to, @_)
                or return undef ;
        }

        return scalar @{ $x-&gt;{Pairs} } ;
    }

    if (! $x-&gt;{oneOutput} )
    {
        my $inFile = ($x-&gt;{inType} eq 'filenames'
                        || $x-&gt;{inType} eq 'filename');

        $x-&gt;{inType} = $inFile ? 'filename' : 'buffer';

        foreach my $in ($x-&gt;{oneInput} ? $input : @$input)
        {
            my $out ;
            $x-&gt;{oneInput} = 1 ;

            $obj-&gt;_singleTarget($x, $inFile, $in, \$out, @_)
                or return undef ;

            push @$output, \$out ;
            #if ($x-&gt;{outType} eq 'array')
            #  { push @$output, \$out }
            #else
            #  { $output-&gt;{$in} = \$out }
        }

        return 1 ;
    }

    # finally the 1 to 1 and n to 1
    return $obj-&gt;_singleTarget($x, 1, $input, $output, @_);

    Carp::croak "should not be here" ;
}

sub _singleTarget
{
    my $obj             = shift ;
    my $x               = shift ;
    my $inputIsFilename = shift;
    my $input           = shift;

    if ($x-&gt;{oneInput})
    {
        $obj-&gt;getFileInfo($x-&gt;{Got}, $input)
            if isaScalar($input) || (isaFilename($input) and $inputIsFilename) ;

        my $z = $obj-&gt;_create($x-&gt;{Got}, @_)
            or return undef ;


        defined $z-&gt;_wr2($input, $inputIsFilename)
            or return $z-&gt;closeError(undef) ;

        return $z-&gt;close() ;
    }
    else
    {
        my $afterFirst = 0 ;
        my $inputIsFilename = ($x-&gt;{inType} ne 'array');
        my $keep = $x-&gt;{Got}-&gt;clone();

        #for my $element ( ($x-&gt;{inType} eq 'hash') ? keys %$input : @$input)
        for my $element ( @$input)
        {
            my $isFilename = isaFilename($element);

            if ( $afterFirst ++ )
            {
                defined addInterStream($obj, $element, $isFilename)
                    or return $obj-&gt;closeError(undef) ;
            }
            else
            {
                $obj-&gt;getFileInfo($x-&gt;{Got}, $element)
                    if isaScalar($element) || $isFilename;

                $obj-&gt;_create($x-&gt;{Got}, @_)
                    or return undef ;
            }

            defined $obj-&gt;_wr2($element, $isFilename)
                or return $obj-&gt;closeError(undef) ;

            *$obj-&gt;{Got} = $keep-&gt;clone();
        }
        return $obj-&gt;close() ;
    }

}

sub _wr2
{
    my $self = shift ;

    my $source = shift ;
    my $inputIsFilename = shift;

    my $input = $source ;
    if (! $inputIsFilename)
    {
        $input = \$source
            if ! ref $source;
    }

    if ( ref $input &amp;&amp; ref $input eq 'SCALAR' )
    {
        return $self-&gt;syswrite($input, @_) ;
    }

    if ( ! ref $input  || isaFilehandle($input))
    {
        my $isFilehandle = isaFilehandle($input) ;

        my $fh = $input ;

        if ( ! $isFilehandle )
        {
            $fh = IO::File-&gt;new( "&lt;$input" )
                or return $self-&gt;saveErrorString(undef, "cannot open file '$input': $!", $!) ;
        }
        binmode $fh ;

        my $status ;
        my $buff ;
        my $count = 0 ;
        while ($status = read($fh, $buff, 16 * 1024)) {
            $count += length $buff;
            defined $self-&gt;syswrite($buff, @_)
                or return undef ;
        }

        return $self-&gt;saveErrorString(undef, $!, $!)
            if ! defined $status ;

        if ( (!$isFilehandle || *$self-&gt;{AutoClose}) &amp;&amp; $input ne '-')
        {
            $fh-&gt;close()
                or return undef ;
        }

        return $count ;
    }

    Carp::croak "Should not be here";
    return undef;
}

sub addInterStream
{
    my $self = shift ;
    my $input = shift ;
    my $inputIsFilename = shift ;

    if (*$self-&gt;{Got}-&gt;getValue('multistream'))
    {
        $self-&gt;getFileInfo(*$self-&gt;{Got}, $input)
            #if isaFilename($input) and $inputIsFilename ;
            if isaScalar($input) || isaFilename($input) ;

        # TODO -- newStream needs to allow gzip/zip header to be modified
        return $self-&gt;newStream();
    }
    elsif (*$self-&gt;{Got}-&gt;getValue('autoflush'))
    {
        #return $self-&gt;flush(Z_FULL_FLUSH);
    }

    return 1 ;
}

sub getFileInfo
{
}

sub TIEHANDLE
{
    return $_[0] if ref($_[0]);
    die "OOPS\n" ;
}

sub UNTIE
{
    my $self = shift ;
}

sub DESTROY
{
    my $self = shift ;
    local ($., $@, $!, $^E, $?);

    $self-&gt;close() ;

    # TODO - memory leak with 5.8.0 - this isn't called until
    #        global destruction
    #
    %{ *$self } = () ;
    undef $self ;
}



sub filterUncompressed
{
}

sub syswrite
{
    my $self = shift ;

    my $buffer ;
    if (ref $_[0] ) {
        $self-&gt;croakError( *$self-&gt;{ClassName} . "::write: not a scalar reference" )
            unless ref $_[0] eq 'SCALAR' ;
        $buffer = $_[0] ;
    }
    else {
        $buffer = \$_[0] ;
    }

    if (@_ &gt; 1) {
        my $slen = defined $$buffer ? length($$buffer) : 0;
        my $len = $slen;
        my $offset = 0;
        $len = $_[1] if $_[1] &lt; $len;

        if (@_ &gt; 2) {
            $offset = $_[2] || 0;
            $self-&gt;croakError(*$self-&gt;{ClassName} . "::write: offset outside string")
                if $offset &gt; $slen;
            if ($offset &lt; 0) {
                $offset += $slen;
                $self-&gt;croakError( *$self-&gt;{ClassName} . "::write: offset outside string") if $offset &lt; 0;
            }
            my $rem = $slen - $offset;
            $len = $rem if $rem &lt; $len;
        }

        $buffer = \substr($$buffer, $offset, $len) ;
    }

    return 0 if (! defined $$buffer || length $$buffer == 0) &amp;&amp; ! *$self-&gt;{FlushPending};

#    *$self-&gt;{Pending} .= $$buffer ;
#
#    return length $$buffer
#        if (length *$self-&gt;{Pending} &lt; 1024 * 16 &amp;&amp; ! *$self-&gt;{FlushPending}) ;
#
#    $$buffer = *$self-&gt;{Pending} ;
#    *$self-&gt;{Pending} = '';

    if (*$self-&gt;{Encoding}) {
        $$buffer = *$self-&gt;{Encoding}-&gt;encode($$buffer);
    }
    else {
        $] &gt;= 5.008 and ( utf8::downgrade($$buffer, 1)
            or Carp::croak "Wide character in " .  *$self-&gt;{ClassName} . "::write:");
    }

    $self-&gt;filterUncompressed($buffer);

    my $buffer_length = defined $$buffer ? length($$buffer) : 0 ;
    *$self-&gt;{UnCompSize}-&gt;add($buffer_length) ;

    my $outBuffer='';
    my $status = *$self-&gt;{Compress}-&gt;compr($buffer, $outBuffer) ;

    return $self-&gt;saveErrorString(undef, *$self-&gt;{Compress}{Error},
                                         *$self-&gt;{Compress}{ErrorNo})
        if $status == STATUS_ERROR;

    *$self-&gt;{CompSize}-&gt;add(length $outBuffer) ;

    $self-&gt;outputPayload($outBuffer)
        or return undef;

    return $buffer_length;
}

sub print
{
    my $self = shift;

    #if (ref $self) {
    #    $self = *$self{GLOB} ;
    #}

    if (defined $\) {
        if (defined $,) {
            defined $self-&gt;syswrite(join($,, @_) . $\);
        } else {
            defined $self-&gt;syswrite(join("", @_) . $\);
        }
    } else {
        if (defined $,) {
            defined $self-&gt;syswrite(join($,, @_));
        } else {
            defined $self-&gt;syswrite(join("", @_));
        }
    }
}

sub printf
{
    my $self = shift;
    my $fmt = shift;
    defined $self-&gt;syswrite(sprintf($fmt, @_));
}

sub _flushCompressed
{
    my $self = shift ;

    my $outBuffer='';
    my $status = *$self-&gt;{Compress}-&gt;flush($outBuffer, @_) ;
    return $self-&gt;saveErrorString(0, *$self-&gt;{Compress}{Error},
                                    *$self-&gt;{Compress}{ErrorNo})
        if $status == STATUS_ERROR;

    if ( defined *$self-&gt;{FH} ) {
        *$self-&gt;{FH}-&gt;clearerr();
    }

    *$self-&gt;{CompSize}-&gt;add(length $outBuffer) ;

    $self-&gt;outputPayload($outBuffer)
        or return 0;
    return 1;
}

sub flush
{
    my $self = shift ;

    $self-&gt;_flushCompressed(@_)
        or return 0;

    if ( defined *$self-&gt;{FH} ) {
        defined *$self-&gt;{FH}-&gt;flush()
            or return $self-&gt;saveErrorString(0, $!, $!);
    }

    return 1;
}

sub beforePayload
{
}

sub _newStream
{
    my $self = shift ;
    my $got  = shift;

    my $class = ref $self;

    $self-&gt;_writeTrailer()
        or return 0 ;

    $self-&gt;ckParams($got)
        or $self-&gt;croakError("newStream: $self-&gt;{Error}");

    if ($got-&gt;getValue('encode')) {
        my $want_encoding = $got-&gt;getValue('encode');
        *$self-&gt;{Encoding} = IO::Compress::Base::Common::getEncoding($self, $class, $want_encoding);
    }
    else {
        *$self-&gt;{Encoding} = undef;
    }

    *$self-&gt;{Compress} = $self-&gt;mkComp($got)
        or return 0;

    *$self-&gt;{Header} = $self-&gt;mkHeader($got) ;
    $self-&gt;output(*$self-&gt;{Header} )
        or return 0;

    *$self-&gt;{UnCompSize}-&gt;reset();
    *$self-&gt;{CompSize}-&gt;reset();

    $self-&gt;beforePayload();

    return 1 ;
}

sub newStream
{
    my $self = shift ;

    my $got = $self-&gt;checkParams('newStream', *$self-&gt;{Got}, @_)
        or return 0 ;

    $self-&gt;_newStream($got);

#    *$self-&gt;{Compress} = $self-&gt;mkComp($got)
#        or return 0;
#
#    *$self-&gt;{Header} = $self-&gt;mkHeader($got) ;
#    $self-&gt;output(*$self-&gt;{Header} )
#        or return 0;
#
#    *$self-&gt;{UnCompSize}-&gt;reset();
#    *$self-&gt;{CompSize}-&gt;reset();
#
#    $self-&gt;beforePayload();
#
#    return 1 ;
}

sub reset
{
    my $self = shift ;
    return *$self-&gt;{Compress}-&gt;reset() ;
}

sub _writeTrailer
{
    my $self = shift ;

    my $trailer = '';

    my $status = *$self-&gt;{Compress}-&gt;close($trailer) ;

    return $self-&gt;saveErrorString(0, *$self-&gt;{Compress}{Error}, *$self-&gt;{Compress}{ErrorNo})
        if $status == STATUS_ERROR;

    *$self-&gt;{CompSize}-&gt;add(length $trailer) ;

    $trailer .= $self-&gt;mkTrailer();
    defined $trailer
      or return 0;
    return $self-&gt;output($trailer);
}

sub _writeFinalTrailer
{
    my $self = shift ;

    return $self-&gt;output($self-&gt;mkFinalTrailer());
}

sub close
{
    my $self = shift ;
    return 1 if *$self-&gt;{Closed} || ! *$self-&gt;{Compress} ;
    *$self-&gt;{Closed} = 1 ;

    untie *$self
        if $] &gt;= 5.008 ;

    *$self-&gt;{FlushPending} = 1 ;
    $self-&gt;_writeTrailer()
        or return 0 ;

    $self-&gt;_writeFinalTrailer()
        or return 0 ;

    $self-&gt;output( "", 1 )
        or return 0;

    if (defined *$self-&gt;{FH}) {

        if ((! *$self-&gt;{Handle} || *$self-&gt;{AutoClose}) &amp;&amp; ! *$self-&gt;{StdIO}) {
            $! = 0 ;
            *$self-&gt;{FH}-&gt;close()
                or return $self-&gt;saveErrorString(0, $!, $!);
        }
        delete *$self-&gt;{FH} ;
        # This delete can set $! in older Perls, so reset the errno
        $! = 0 ;
    }

    return 1;
}


#sub total_in
#sub total_out
#sub msg
#
#sub crc
#{
#    my $self = shift ;
#    return *$self-&gt;{Compress}-&gt;crc32() ;
#}
#
#sub msg
#{
#    my $self = shift ;
#    return *$self-&gt;{Compress}-&gt;msg() ;
#}
#
#sub dict_adler
#{
#    my $self = shift ;
#    return *$self-&gt;{Compress}-&gt;dict_adler() ;
#}
#
#sub get_Level
#{
#    my $self = shift ;
#    return *$self-&gt;{Compress}-&gt;get_Level() ;
#}
#
#sub get_Strategy
#{
#    my $self = shift ;
#    return *$self-&gt;{Compress}-&gt;get_Strategy() ;
#}


sub tell
{
    my $self = shift ;

    return *$self-&gt;{UnCompSize}-&gt;get32bit() ;
}

sub eof
{
    my $self = shift ;

    return *$self-&gt;{Closed} ;
}


sub seek
{
    my $self     = shift ;
    my $position = shift;
    my $whence   = shift ;

    my $here = $self-&gt;tell() ;
    my $target = 0 ;

    #use IO::Handle qw(SEEK_SET SEEK_CUR SEEK_END);
    use IO::Handle ;

    if ($whence == IO::Handle::SEEK_SET) {
        $target = $position ;
    }
    elsif ($whence == IO::Handle::SEEK_CUR || $whence == IO::Handle::SEEK_END) {
        $target = $here + $position ;
    }
    else {
        $self-&gt;croakError(*$self-&gt;{ClassName} . "::seek: unknown value, $whence, for whence parameter");
    }

    # short circuit if seeking to current offset
    return 1 if $target == $here ;

    # Outlaw any attempt to seek backwards
    $self-&gt;croakError(*$self-&gt;{ClassName} . "::seek: cannot seek backwards")
        if $target &lt; $here ;

    # Walk the file to the new offset
    my $offset = $target - $here ;

    my $buffer ;
    defined $self-&gt;syswrite("\x00" x $offset)
        or return 0;

    return 1 ;
}

sub binmode
{
    1;
#    my $self     = shift ;
#    return defined *$self-&gt;{FH}
#            ? binmode *$self-&gt;{FH}
#            : 1 ;
}

sub fileno
{
    my $self     = shift ;
    return defined *$self-&gt;{FH}
            ? *$self-&gt;{FH}-&gt;fileno()
            : undef ;
}

sub opened
{
    my $self     = shift ;
    return ! *$self-&gt;{Closed} ;
}

sub autoflush
{
    my $self     = shift ;
    return defined *$self-&gt;{FH}
            ? *$self-&gt;{FH}-&gt;autoflush(@_)
            : undef ;
}

sub input_line_number
{
    return undef ;
}


sub _notAvailable
{
    my $name = shift ;
    return sub { Carp::croak "$name Not Available: File opened only for output" ; } ;
}

{
    no warnings 'once';

    *read     = _notAvailable('read');
    *READ     = _notAvailable('read');
    *readline = _notAvailable('readline');
    *READLINE = _notAvailable('readline');
    *getc     = _notAvailable('getc');
    *GETC     = _notAvailable('getc');

    *FILENO   = \&amp;fileno;
    *PRINT    = \&amp;print;
    *PRINTF   = \&amp;printf;
    *WRITE    = \&amp;syswrite;
    *write    = \&amp;syswrite;
    *SEEK     = \&amp;seek;
    *TELL     = \&amp;tell;
    *EOF      = \&amp;eof;
    *CLOSE    = \&amp;close;
    *BINMODE  = \&amp;binmode;
}

#*sysread  = \&amp;_notAvailable;
#*syswrite = \&amp;_write;

1;

__END__

=head1 NAME

IO::Compress::Base - Base Class for IO::Compress modules

=head1 SYNOPSIS

    use IO::Compress::Base ;

=head1 DESCRIPTION

This module is not intended for direct use in application code. Its sole
purpose is to be sub-classed by IO::Compress modules.

=head1 SUPPORT

General feedback/questions/bug reports should be sent to
L&lt;https://github.com/pmqs/IO-Compress/issues&gt; (preferred) or
L&lt;https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress&gt;.

=head1 SEE ALSO

L&lt;Compress::Zlib&gt;, L&lt;IO::Compress::Gzip&gt;, L&lt;IO::Uncompress::Gunzip&gt;, L&lt;IO::Compress::Deflate&gt;, L&lt;IO::Uncompress::Inflate&gt;, L&lt;IO::Compress::RawDeflate&gt;, L&lt;IO::Uncompress::RawInflate&gt;, L&lt;IO::Compress::Bzip2&gt;, L&lt;IO::Uncompress::Bunzip2&gt;, L&lt;IO::Compress::Lzma&gt;, L&lt;IO::Uncompress::UnLzma&gt;, L&lt;IO::Compress::Xz&gt;, L&lt;IO::Uncompress::UnXz&gt;, L&lt;IO::Compress::Lzip&gt;, L&lt;IO::Uncompress::UnLzip&gt;, L&lt;IO::Compress::Lzop&gt;, L&lt;IO::Uncompress::UnLzop&gt;, L&lt;IO::Compress::Lzf&gt;, L&lt;IO::Uncompress::UnLzf&gt;, L&lt;IO::Compress::Zstd&gt;, L&lt;IO::Uncompress::UnZstd&gt;, L&lt;IO::Uncompress::AnyInflate&gt;, L&lt;IO::Uncompress::AnyUncompress&gt;

L&lt;IO::Compress::FAQ|IO::Compress::FAQ&gt;

L&lt;File::GlobMapper|File::GlobMapper&gt;, L&lt;Archive::Zip|Archive::Zip&gt;,
L&lt;Archive::Tar|Archive::Tar&gt;,
L&lt;IO::Zlib|IO::Zlib&gt;

=head1 AUTHOR

This module was written by Paul Marquess, C&lt;pmqs@cpan.org&gt;.

=head1 MODIFICATION HISTORY

See the Changes file.

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2005-2024 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.
</pre></body></html>