GIF89a;
EcchiShell v1.0
/
/
proc/
self/
root/
usr/
share/
perl5/
_create(undef, 0, @_);
}
sub gunzip
{
my $obj = IO::Compress::Base::Common::createSelfTiedObject(undef, \$GunzipError);
return $obj->_inf(@_) ;
}
sub getExtraParams
{
return ( 'parseextra' => [IO::Compress::Base::Common::Parse_boolean, 0] ) ;
}
sub ckParams
{
my $self = shift ;
my $got = shift ;
# gunzip always needs crc32
$got->setValue('crc32' => 1);
return 1;
}
sub ckMagic
{
my $self = shift;
my $magic ;
$self->smartReadExact(\$magic, GZIP_ID_SIZE);
*$self->{HeaderPending} = $magic ;
return $self->HeaderError("Minimum header size is " .
GZIP_MIN_HEADER_SIZE . " bytes")
if length $magic != GZIP_ID_SIZE ;
return $self->HeaderError("Bad Magic")
if ! isGzipMagic($magic) ;
*$self->{Type} = 'rfc1952';
return $magic ;
}
sub readHeader
{
my $self = shift;
my $magic = shift;
return $self->_readGzipHeader($magic);
}
sub chkTrailer
{
my $self = shift;
my $trailer = shift;
# Check CRC & ISIZE
my ($CRC32, $ISIZE) = unpack("V V", $trailer) ;
*$self->{Info}{CRC32} = $CRC32;
*$self->{Info}{ISIZE} = $ISIZE;
if (*$self->{Strict}) {
return $self->TrailerError("CRC mismatch")
if $CRC32 != *$self->{Uncomp}->crc32() ;
my $exp_isize = *$self->{UnCompSize}->get32bit();
return $self->TrailerError("ISIZE mismatch. Got $ISIZE"
. ", expected $exp_isize")
if $ISIZE != $exp_isize ;
}
return STATUS_OK;
}
sub isGzipMagic
{
my $buffer = shift ;
return 0 if length $buffer < GZIP_ID_SIZE ;
my ($id1, $id2) = unpack("C C", $buffer) ;
return $id1 == GZIP_ID1 && $id2 == GZIP_ID2 ;
}
sub _readFullGzipHeader($)
{
my ($self) = @_ ;
my $magic = '' ;
$self->smartReadExact(\$magic, GZIP_ID_SIZE);
*$self->{HeaderPending} = $magic ;
return $self->HeaderError("Minimum header size is " .
GZIP_MIN_HEADER_SIZE . " bytes")
if length $magic != GZIP_ID_SIZE ;
return $self->HeaderError("Bad Magic")
if ! isGzipMagic($magic) ;
my $status = $self->_readGzipHeader($magic);
delete *$self->{Transparent} if ! defined $status ;
return $status ;
}
sub _readGzipHeader($)
{
my ($self, $magic) = @_ ;
my ($HeaderCRC) ;
my ($buffer) = '' ;
$self->smartReadExact(\$buffer, GZIP_MIN_HEADER_SIZE - GZIP_ID_SIZE)
or return $self->HeaderError("Minimum header size is " .
GZIP_MIN_HEADER_SIZE . " bytes") ;
my $keep = $magic . $buffer ;
*$self->{HeaderPending} = $keep ;
# now split out the various parts
my ($cm, $flag, $mtime, $xfl, $os) = unpack("C C V C C", $buffer) ;
$cm == GZIP_CM_DEFLATED
or return $self->HeaderError("Not Deflate (CM is $cm)") ;
# check for use of reserved bits
return $self->HeaderError("Use of Reserved Bits in FLG field.")
if $flag & GZIP_FLG_RESERVED ;
my $EXTRA ;
my @EXTRA = () ;
if ($flag & GZIP_FLG_FEXTRA) {
$EXTRA = "" ;
$self->smartReadExact(\$buffer, GZIP_FEXTRA_HEADER_SIZE)
or return $self->TruncatedHeader("FEXTRA Length") ;
my ($XLEN) = unpack("v", $buffer) ;
$self->smartReadExact(\$EXTRA, $XLEN)
or return $self->TruncatedHeader("FEXTRA Body");
$keep .= $buffer . $EXTRA ;
if ($XLEN && *$self->{'ParseExtra'}) {
my $bad = IO::Compress::Zlib::Extra::parseRawExtra($EXTRA,
\@EXTRA, 1, 1);
return $self->HeaderError($bad)
if defined $bad;
}
}
my $origname ;
if ($flag & GZIP_FLG_FNAME) {
$origname = "" ;
while (1) {
$self->smartReadExact(\$buffer, 1)
or return $self->TruncatedHeader("FNAME");
last if $buffer eq GZIP_NULL_BYTE ;
$origname .= $buffer
}
$keep .= $origname . GZIP_NULL_BYTE ;
return $self->HeaderError("Non ISO 8859-1 Character found in Name")
if *$self->{Strict} && $origname =~ /$GZIP_FNAME_INVALID_CHAR_RE/o ;
}
my $comment ;
if ($flag & GZIP_FLG_FCOMMENT) {
$comment = "";
while (1) {
$self->smartReadExact(\$buffer, 1)
or return $self->TruncatedHeader("FCOMMENT");
last if $buffer eq GZIP_NULL_BYTE ;
$comment .= $buffer
}
$keep .= $comment . GZIP_NULL_BYTE ;
return $self->HeaderError("Non ISO 8859-1 Character found in Comment")
if *$self->{Strict} && $comment =~ /$GZIP_FCOMMENT_INVALID_CHAR_RE/o ;
}
if ($flag & GZIP_FLG_FHCRC) {
$self->smartReadExact(\$buffer, GZIP_FHCRC_SIZE)
or return $self->TruncatedHeader("FHCRC");
$HeaderCRC = unpack("v", $buffer) ;
my $crc16 = Compress::Raw::Zlib::crc32($keep) & 0xFF ;
return $self->HeaderError("CRC16 mismatch.")
if *$self->{Strict} && $crc16 != $HeaderCRC;
$keep .= $buffer ;
}
# Assume compression method is deflated for xfl tests
#if ($xfl) {
#}
*$self->{Type} = 'rfc1952';
return {
'Type' => 'rfc1952',
'FingerprintLength' => 2,
'HeaderLength' => length $keep,
'TrailerLength' => GZIP_TRAILER_SIZE,
'Header' => $keep,
'isMinimalHeader' => $keep eq GZIP_MINIMUM_HEADER ? 1 : 0,
'MethodID' => $cm,
'MethodName' => $cm == GZIP_CM_DEFLATED ? "Deflated" : "Unknown" ,
'TextFlag' => $flag & GZIP_FLG_FTEXT ? 1 : 0,
'HeaderCRCFlag' => $flag & GZIP_FLG_FHCRC ? 1 : 0,
'NameFlag' => $flag & GZIP_FLG_FNAME ? 1 : 0,
'CommentFlag' => $flag & GZIP_FLG_FCOMMENT ? 1 : 0,
'ExtraFlag' => $flag & GZIP_FLG_FEXTRA ? 1 : 0,
'Name' => $origname,
'Comment' => $comment,
'Time' => $mtime,
'OsID' => $os,
'OsName' => defined $GZIP_OS_Names{$os}
? $GZIP_OS_Names{$os} : "Unknown",
'HeaderCRC' => $HeaderCRC,
'Flags' => $flag,
'ExtraFlags' => $xfl,
'ExtraFieldRaw' => $EXTRA,
'ExtraField' => [ @EXTRA ],
#'CompSize'=> $compsize,
#'CRC32'=> $CRC32,
#'OrigSize'=> $ISIZE,
}
}
1;
__END__
=head1 NAME
IO::Uncompress::Gunzip - Read RFC 1952 files/buffers
=head1 SYNOPSIS
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
my $status = gunzip $input => $output [,OPTS]
or die "gunzip failed: $GunzipError\n";
my $z = new IO::Uncompress::Gunzip $input [OPTS]
or die "gunzip failed: $GunzipError\n";
$status = $z->read($buffer)
$status = $z->read($buffer, $length)
$status = $z->read($buffer, $length, $offset)
$line = $z->getline()
$char = $z->getc()
$char = $z->ungetc()
$char = $z->opened()
$status = $z->inflateSync()
$data = $z->trailingData()
$status = $z->nextStream()
$data = $z->getHeaderInfo()
$z->tell()
$z->seek($position, $whence)
$z->binmode()
$z->fileno()
$z->eof()
$z->close()
$GunzipError ;
# IO::File mode
<$z>
read($z, $buffer);
read($z, $buffer, $length);
read($z, $buffer, $length, $offset);
tell($z)
seek($z, $position, $whence)
binmode($z)
fileno($z)
eof($z)
close($z)
=head1 DESCRIPTION
This module provides a Perl interface that allows the reading of
files/buffers that conform to RFC 1952.
For writing RFC 1952 files/buffers, see the companion module IO::Compress::Gzip.
=head1 Functional Interface
A top-level function, C, is provided to carry out
"one-shot" uncompression between buffers and/or files. For finer
control over the uncompression process, see the L"OO Interface">
section.
use IO::Uncompress::Gunzip qw(gunzip $GunzipError) ;
gunzip $input_filename_or_reference => $output_filename_or_reference [,OPTS]
or die "gunzip failed: $GunzipError\n";
The functional interface needs Perl5.005 or better.
=head2 gunzip $input_filename_or_reference => $output_filename_or_reference [, OPTS]
C expects at least two parameters,
C<$input_filename_or_reference> and C<$output_filename_or_reference>.
=head3 The C<$input_filename_or_reference> parameter
The parameter, C<$input_filename_or_reference>, is used to define the
source of the compressed data.
It can take one of the following forms:
=over 5
=item A filename
If the <$input_filename_or_reference> parameter is a simple scalar, it is
assumed to be a filename. This file will be opened for reading and the
input data will be read from it.
=item A filehandle
If the C<$input_filename_or_reference> parameter is a filehandle, the input
data will be read from it. The string '-' can be used as an alias for
standard input.
=item A scalar reference
If C<$input_filename_or_reference> is a scalar reference, the input data
will be read from C<$$input_filename_or_reference>.
=item An array reference
If C<$input_filename_or_reference> is an array reference, each element in
the array must be a filename.
The input data will be read from each file in turn.
The complete array will be walked to ensure that it only
contains valid filenames before any data is uncompressed.
=item An Input FileGlob string
If C<$input_filename_or_reference> is a string that is delimited by the
characters "<" and ">" C will assume that it is an
I. The input is the list of files that match the
fileglob.
See L for more details.
=back
If the C<$input_filename_or_reference> parameter is any other type,
C will be returned.
=head3 The C<$output_filename_or_reference> parameter
The parameter C<$output_filename_or_reference> is used to control the
destination of the uncompressed data. This parameter can take one of
these forms.
=over 5
=item A filename
If the C<$output_filename_or_reference> parameter is a simple scalar, it is
assumed to be a filename. This file will be opened for writing and the
uncompressed data will be written to it.
=item A filehandle
If the C<$output_filename_or_reference> parameter is a filehandle, the
uncompressed data will be written to it. The string '-' can be used as
an alias for standard output.
=item A scalar reference
If C<$output_filename_or_reference> is a scalar reference, the
uncompressed data will be stored in C<$$output_filename_or_reference>.
=item An Array Reference
If C<$output_filename_or_reference> is an array reference,
the uncompressed data will be pushed onto the array.
=item An Output FileGlob
If C<$output_filename_or_reference> is a string that is delimited by the
characters "<" and ">" C will assume that it is an
I