package IO::Uncompress::Base ;
use strict ;
use warnings;
use bytes;
our (@ISA, $VERSION, @EXPORT_OK, %EXPORT_TAGS);
@ISA = qw(Exporter IO::File);
$VERSION = '2.015';
use constant G_EOF => 0 ;
use constant G_ERR => -1 ;
use IO::Compress::Base::Common 2.015 ;
#use Parse::Parameters ;
use IO::File ;
use Symbol;
use Scalar::Util qw(readonly);
use List::Util qw(min);
use Carp ;
%EXPORT_TAGS = ( );
push @{ $EXPORT_TAGS{all} }, @EXPORT_OK ;
#Exporter::export_ok_tags('all') ;
sub smartRead
{
my $self = $_[0];
my $out = $_[1];
my $size = $_[2];
$$out = "" ;
my $offset = 0 ;
if (defined *$self->{InputLength}) {
return 0
if *$self->{InputLengthRemaining} <= 0 ;
$size = min($size, *$self->{InputLengthRemaining});
}
if ( length *$self->{Prime} ) {
#$$out = substr(*$self->{Prime}, 0, $size, '') ;
$$out = substr(*$self->{Prime}, 0, $size) ;
substr(*$self->{Prime}, 0, $size) = '' ;
if (length $$out == $size) {
*$self->{InputLengthRemaining} -= length $$out
if defined *$self->{InputLength};
return length $$out ;
}
$offset = length $$out ;
}
my $get_size = $size - $offset ;
if (defined *$self->{FH}) {
if ($offset) {
# Not using this
#
# *$self->{FH}->read($$out, $get_size, $offset);
#
# because the filehandle may not support the offset parameter
# An example is Net::FTP
my $tmp = '';
*$self->{FH}->read($tmp, $get_size) > 0 &&
(substr($$out, $offset) = $tmp);
}
else
{ *$self->{FH}->read($$out, $get_size) }
}
elsif (defined *$self->{InputEvent}) {
my $got = 1 ;
while (length $$out < $size) {
last
if ($got = *$self->{InputEvent}->($$out, $get_size)) <= 0;
}
if (length $$out > $size ) {
#*$self->{Prime} = substr($$out, $size, length($$out), '');
*$self->{Prime} = substr($$out, $size, length($$out));
substr($$out, $size, length($$out)) = '';
}
*$self->{EventEof} = 1 if $got <= 0 ;
}
else {
no warnings 'uninitialized';
my $buf = *$self->{Buffer} ;
$$buf = '' unless defined $$buf ;
#$$out = '' unless defined $$out ;
substr($$out, $offset) = substr($$buf, *$self->{BufferOffset}, $get_size);
if (*$self->{ConsumeInput})
{ substr($$buf, 0, $get_size) = '' }
=1= |