📄 base.pm
字号:
} } push @{ *$self->{InfoList} }, *$self->{Info} ; return 1; }sub streamCount{ my $self = shift ; return 1 if ! defined *$self->{InfoList}; return scalar @{ *$self->{InfoList} } ;}sub read{ # return codes # >0 - ok, number of bytes read # =0 - ok, eof # <0 - not ok my $self = shift ; return G_EOF if *$self->{Closed} ; my $buffer ; if (ref $_[0] ) { $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only") if readonly(${ $_[0] }); $self->croakError(*$self->{ClassName} . "::read: not a scalar reference $_[0]" ) unless ref $_[0] eq 'SCALAR' ; $buffer = $_[0] ; } else { $self->croakError(*$self->{ClassName} . "::read: buffer parameter is read-only") if readonly($_[0]); $buffer = \$_[0] ; } my $length = $_[1] ; my $offset = $_[2] || 0; if (! *$self->{AppendOutput}) { if (! $offset) { $$buffer = '' ; } else { if ($offset > length($$buffer)) { $$buffer .= "\x00" x ($offset - length($$buffer)); } else { substr($$buffer, $offset) = ''; } } } return G_EOF if !length *$self->{Pending} && *$self->{EndStream} ; # the core read will return 0 if asked for 0 bytes return 0 if defined $length && $length == 0 ; $length = $length || 0; $self->croakError(*$self->{ClassName} . "::read: length parameter is negative") if $length < 0 ; # Short-circuit if this is a simple read, with no length # or offset specified. unless ( $length || $offset) { if (length *$self->{Pending}) { $$buffer .= *$self->{Pending} ; my $len = length *$self->{Pending}; *$self->{Pending} = '' ; return $len ; } else { my $len = 0; $len = $self->_raw_read($buffer) while ! *$self->{EndStream} && $len == 0 ; return $len ; } } # Need to jump through more hoops - either length or offset # or both are specified. my $out_buffer = *$self->{Pending} ; while (! *$self->{EndStream} && length($out_buffer) < $length) { my $buf_len = $self->_raw_read(\$out_buffer); return $buf_len if $buf_len < 0 ; } $length = length $out_buffer if length($out_buffer) < $length ; return 0 if $length == 0 ; $$buffer = '' if ! defined $$buffer; $offset = length $$buffer if *$self->{AppendOutput} ; *$self->{Pending} = $out_buffer; $out_buffer = \*$self->{Pending} ; #substr($$buffer, $offset) = substr($$out_buffer, 0, $length, '') ; substr($$buffer, $offset) = substr($$out_buffer, 0, $length) ; substr($$out_buffer, 0, $length) = '' ; return $length ;}sub _getline{ my $self = shift ; # Slurp Mode if ( ! defined $/ ) { my $data ; 1 while $self->read($data) > 0 ; return \$data ; } # Record Mode if ( ref $/ eq 'SCALAR' && ${$/} =~ /^\d+$/ && ${$/} > 0) { my $reclen = ${$/} ; my $data ; $self->read($data, $reclen) ; return \$data ; } # Paragraph Mode if ( ! length $/ ) { my $paragraph ; while ($self->read($paragraph) > 0 ) { if ($paragraph =~ s/^(.*?\n\n+)//s) { *$self->{Pending} = $paragraph ; my $par = $1 ; return \$par ; } } return \$paragraph; } # $/ isn't empty, or a reference, so it's Line Mode. { my $line ; my $offset; my $p = \*$self->{Pending} ; if (length(*$self->{Pending}) && ($offset = index(*$self->{Pending}, $/)) >=0) { my $l = substr(*$self->{Pending}, 0, $offset + length $/ ); substr(*$self->{Pending}, 0, $offset + length $/) = ''; return \$l; } while ($self->read($line) > 0 ) { my $offset = index($line, $/); if ($offset >= 0) { my $l = substr($line, 0, $offset + length $/ ); substr($line, 0, $offset + length $/) = ''; $$p = $line; return \$l; } } return \$line; }}sub getline{ my $self = shift; my $current_append = *$self->{AppendOutput} ; *$self->{AppendOutput} = 1; my $lineref = $self->_getline(); $. = ++ *$self->{LineNo} if defined $$lineref ; *$self->{AppendOutput} = $current_append; return $$lineref ;}sub getlines{ my $self = shift; $self->croakError(*$self->{ClassName} . "::getlines: called in scalar context\n") unless wantarray; my($line, @lines); push(@lines, $line) while defined($line = $self->getline); return @lines;}sub READLINE{ goto &getlines if wantarray; goto &getline;}sub getc{ my $self = shift; my $buf; return $buf if $self->read($buf, 1); return undef;}sub ungetc{ my $self = shift; *$self->{Pending} = "" unless defined *$self->{Pending} ; *$self->{Pending} = $_[0] . *$self->{Pending} ; }sub trailingData{ my $self = shift ; if (defined *$self->{FH} || defined *$self->{InputEvent} ) { return *$self->{Prime} ; } else { my $buf = *$self->{Buffer} ; my $offset = *$self->{BufferOffset} ; return substr($$buf, $offset) ; }}sub eof{ my $self = shift ; return (*$self->{Closed} || (!length *$self->{Pending} && ( $self->smartEof() || *$self->{EndStream}))) ;}sub tell{ my $self = shift ; my $in ; if (*$self->{Plain}) { $in = *$self->{PlainBytesRead} ; } else { $in = *$self->{TotalInflatedBytesRead} ; } my $pending = length *$self->{Pending} ; return 0 if $pending > $in ; return $in - $pending ;}sub close{ # todo - what to do if close is called before the end of the gzip file # do we remember any trailing data? my $self = shift ; return 1 if *$self->{Closed} ; untie *$self if $] >= 5.008 ; my $status = 1 ; if (defined *$self->{FH}) { if ((! *$self->{Handle} || *$self->{AutoClose}) && ! *$self->{StdIO}) { #if ( *$self->{AutoClose}) { local $.; $! = 0 ; $status = *$self->{FH}->close(); return $self->saveErrorString(0, $!, $!) if !*$self->{InNew} && $self->saveStatus($!) != 0 ; } delete *$self->{FH} ; $! = 0 ; } *$self->{Closed} = 1 ; return 1;}sub DESTROY{ my $self = shift ; $self->close() ;}sub seek{ my $self = shift ; my $position = shift; my $whence = shift ; my $here = $self->tell() ; my $target = 0 ; if ($whence == SEEK_SET) { $target = $position ; } elsif ($whence == SEEK_CUR) { $target = $here + $position ; } elsif ($whence == SEEK_END) { $target = $position ; $self->croakError(*$self->{ClassName} . "::seek: SEEK_END not allowed") ; } else { $self->croakError(*$self->{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->croakError( *$self->{ClassName} ."::seek: cannot seek backwards") if $target < $here ; # Walk the file to the new offset my $offset = $target - $here ; my $got; while (($got = $self->read(my $buffer, min($offset, *$self->{BlockSize})) ) > 0) { $offset -= $got; last if $offset == 0 ; } return $offset == 0 ? 1 : 0 ;}sub fileno{ my $self = shift ; return defined *$self->{FH} ? fileno *$self->{FH} : undef ;}sub binmode{ 1;# my $self = shift ;# return defined *$self->{FH} # ? binmode *$self->{FH} # : 1 ;}sub opened{ my $self = shift ; return ! *$self->{Closed} ;}sub autoflush{ my $self = shift ; return defined *$self->{FH} ? *$self->{FH}->autoflush(@_) : undef ;}sub input_line_number{ my $self = shift ; my $last = *$self->{LineNo}; $. = *$self->{LineNo} = $_[1] if @_ ; return $last;}*BINMODE = \&binmode;*SEEK = \&seek; *READ = \&read;*sysread = \&read;*TELL = \&tell;*EOF = \&eof;*FILENO = \&fileno;*CLOSE = \&close;sub _notAvailable{ my $name = shift ; #return sub { croak "$name Not Available" ; } ; return sub { croak "$name Not Available: File opened only for intput" ; } ;}*print = _notAvailable('print');*PRINT = _notAvailable('print');*printf = _notAvailable('printf');*PRINTF = _notAvailable('printf');*write = _notAvailable('write');*WRITE = _notAvailable('write');#*sysread = \&read;#*syswrite = \&_notAvailable;package IO::Uncompress::Base ;1 ;__END__=head1 NAMEIO::Uncompress::Base - Base Class for IO::Uncompress modules =head1 SYNOPSIS use IO::Uncompress::Base ;=head1 DESCRIPTIONThis module is not intended for direct use in application code. Its solepurpose if to to be sub-classed by IO::Unompress modules.=head1 SEE ALSOL<Compress::Zlib>, L<IO::Compress::Gzip>, L<IO::Uncompress::Gunzip>, L<IO::Compress::Deflate>, L<IO::Uncompress::Inflate>, L<IO::Compress::RawDeflate>, L<IO::Uncompress::RawInflate>, L<IO::Compress::Bzip2>, L<IO::Uncompress::Bunzip2>, L<IO::Compress::Lzop>, L<IO::Uncompress::UnLzop>, L<IO::Compress::Lzf>, L<IO::Uncompress::UnLzf>, L<IO::Uncompress::AnyInflate>, L<IO::Uncompress::AnyUncompress>L<Compress::Zlib::FAQ|Compress::Zlib::FAQ>L<File::GlobMapper|File::GlobMapper>, L<Archive::Zip|Archive::Zip>,L<Archive::Tar|Archive::Tar>,L<IO::Zlib|IO::Zlib>=head1 AUTHORThis module was written by Paul Marquess, F<pmqs@cpan.org>. =head1 MODIFICATION HISTORYSee the Changes file.=head1 COPYRIGHT AND LICENSECopyright (c) 2005-2007 Paul Marquess. All rights reserved.This program is free software; you can redistribute it and/ormodify it under the same terms as Perl itself.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -