Initial Commit
This commit is contained in:
111
database/perl/lib/IO/Uncompress/Adapter/Bunzip2.pm
Normal file
111
database/perl/lib/IO/Uncompress/Adapter/Bunzip2.pm
Normal file
@@ -0,0 +1,111 @@
|
||||
package IO::Uncompress::Adapter::Bunzip2;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use bytes;
|
||||
|
||||
use IO::Compress::Base::Common 2.100 qw(:Status);
|
||||
|
||||
use Compress::Raw::Bzip2 2.100 ;
|
||||
|
||||
our ($VERSION, @ISA);
|
||||
$VERSION = '2.100';
|
||||
|
||||
sub mkUncompObject
|
||||
{
|
||||
my $small = shift || 0;
|
||||
my $verbosity = shift || 0;
|
||||
|
||||
my ($inflate, $status) = Compress::Raw::Bunzip2->new(1, 1, $small, $verbosity, 1);
|
||||
|
||||
return (undef, "Could not create Inflation object: $status", $status)
|
||||
if $status != BZ_OK ;
|
||||
|
||||
return bless {'Inf' => $inflate,
|
||||
'CompSize' => 0,
|
||||
'UnCompSize' => 0,
|
||||
'Error' => '',
|
||||
'ConsumesInput' => 1,
|
||||
} ;
|
||||
|
||||
}
|
||||
|
||||
sub uncompr
|
||||
{
|
||||
my $self = shift ;
|
||||
my $from = shift ;
|
||||
my $to = shift ;
|
||||
my $eof = shift ;
|
||||
|
||||
my $inf = $self->{Inf};
|
||||
|
||||
my $status = $inf->bzinflate($from, $to);
|
||||
$self->{ErrorNo} = $status;
|
||||
|
||||
if ($status != BZ_OK && $status != BZ_STREAM_END )
|
||||
{
|
||||
$self->{Error} = "Inflation Error: $status";
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
|
||||
return STATUS_OK if $status == BZ_OK ;
|
||||
return STATUS_ENDSTREAM if $status == BZ_STREAM_END ;
|
||||
return STATUS_ERROR ;
|
||||
}
|
||||
|
||||
|
||||
sub reset
|
||||
{
|
||||
my $self = shift ;
|
||||
|
||||
my ($inf, $status) = Compress::Raw::Bunzip2->new();
|
||||
$self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ;
|
||||
|
||||
if ($status != BZ_OK)
|
||||
{
|
||||
$self->{Error} = "Cannot create Inflate object: $status";
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
$self->{Inf} = $inf;
|
||||
|
||||
return STATUS_OK ;
|
||||
}
|
||||
|
||||
sub compressedBytes
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->compressedBytes();
|
||||
}
|
||||
|
||||
sub uncompressedBytes
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->uncompressedBytes();
|
||||
}
|
||||
|
||||
sub crc32
|
||||
{
|
||||
my $self = shift ;
|
||||
#$self->{Inf}->crc32();
|
||||
}
|
||||
|
||||
sub adler32
|
||||
{
|
||||
my $self = shift ;
|
||||
#$self->{Inf}->adler32();
|
||||
}
|
||||
|
||||
sub sync
|
||||
{
|
||||
my $self = shift ;
|
||||
#( $self->{Inf}->inflateSync(@_) == BZ_OK)
|
||||
# ? STATUS_OK
|
||||
# : STATUS_ERROR ;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
188
database/perl/lib/IO/Uncompress/Adapter/Identity.pm
Normal file
188
database/perl/lib/IO/Uncompress/Adapter/Identity.pm
Normal file
@@ -0,0 +1,188 @@
|
||||
package IO::Uncompress::Adapter::Identity;
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use bytes;
|
||||
|
||||
use IO::Compress::Base::Common 2.100 qw(:Status);
|
||||
use IO::Compress::Zip::Constants ;
|
||||
|
||||
our ($VERSION);
|
||||
|
||||
$VERSION = '2.100';
|
||||
|
||||
use Compress::Raw::Zlib 2.100 ();
|
||||
|
||||
sub mkUncompObject
|
||||
{
|
||||
my $streaming = shift;
|
||||
my $zip64 = shift;
|
||||
|
||||
my $crc32 = 1; #shift ;
|
||||
my $adler32 = shift;
|
||||
|
||||
bless { 'CompSize' => U64->new(), # 0,
|
||||
'UnCompSize' => 0,
|
||||
'wantCRC32' => $crc32,
|
||||
'CRC32' => Compress::Raw::Zlib::crc32(''),
|
||||
'wantADLER32'=> $adler32,
|
||||
'ADLER32' => Compress::Raw::Zlib::adler32(''),
|
||||
'ConsumesInput' => 1,
|
||||
'Streaming' => $streaming,
|
||||
'Zip64' => $zip64,
|
||||
'DataHdrSize' => $zip64 ? 24 : 16,
|
||||
'Pending' => '',
|
||||
|
||||
} ;
|
||||
}
|
||||
|
||||
|
||||
sub uncompr
|
||||
{
|
||||
my $self = shift;
|
||||
my $in = $_[0];
|
||||
my $eof = $_[2];
|
||||
|
||||
my $len = length $$in;
|
||||
my $remainder = '';
|
||||
|
||||
if (defined $$in && $len) {
|
||||
|
||||
if ($self->{Streaming}) {
|
||||
|
||||
if (length $self->{Pending}) {
|
||||
$$in = $self->{Pending} . $$in ;
|
||||
$len = length $$in;
|
||||
$self->{Pending} = '';
|
||||
}
|
||||
|
||||
my $ind = index($$in, "\x50\x4b\x07\x08");
|
||||
|
||||
if ($ind < 0) {
|
||||
$len = length $$in;
|
||||
if ($len >= 3 && substr($$in, -3) eq "\x50\x4b\x07") {
|
||||
$ind = $len - 3 ;
|
||||
}
|
||||
elsif ($len >= 2 && substr($$in, -2) eq "\x50\x4b") {
|
||||
$ind = $len - 2 ;
|
||||
}
|
||||
elsif ($len >= 1 && substr($$in, -1) eq "\x50") {
|
||||
$ind = $len - 1 ;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ind >= 0) {
|
||||
$remainder = substr($$in, $ind) ;
|
||||
substr($$in, $ind) = '' ;
|
||||
}
|
||||
}
|
||||
|
||||
if (length $remainder && length $remainder < $self->{DataHdrSize}) {
|
||||
$self->{Pending} = $remainder ;
|
||||
$remainder = '';
|
||||
}
|
||||
elsif (length $remainder >= $self->{DataHdrSize}) {
|
||||
my $crc = unpack "V", substr($remainder, 4);
|
||||
if ($crc == Compress::Raw::Zlib::crc32($$in, $self->{CRC32})) {
|
||||
my ($l1, $l2) ;
|
||||
|
||||
if ($self->{Zip64}) {
|
||||
$l1 = U64::newUnpack_V64(substr($remainder, 8));
|
||||
$l2 = U64::newUnpack_V64(substr($remainder, 16));
|
||||
}
|
||||
else {
|
||||
$l1 = U64::newUnpack_V32(substr($remainder, 8));
|
||||
$l2 = U64::newUnpack_V32(substr($remainder, 12));
|
||||
}
|
||||
|
||||
my $newLen = $self->{CompSize}->clone();
|
||||
$newLen->add(length $$in);
|
||||
if ($l1->equal($l2) && $l1->equal($newLen) ) {
|
||||
$eof = 1;
|
||||
}
|
||||
else {
|
||||
$$in .= substr($remainder, 0, 4) ;
|
||||
$remainder = substr($remainder, 4);
|
||||
#$self->{Pending} = substr($remainder, 4);
|
||||
#$remainder = '';
|
||||
$eof = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$$in .= substr($remainder, 0, 4) ;
|
||||
$remainder = substr($remainder, 4);
|
||||
#$self->{Pending} = substr($remainder, 4);
|
||||
#$remainder = '';
|
||||
$eof = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (length $$in) {
|
||||
$self->{CompSize}->add(length $$in) ;
|
||||
|
||||
$self->{CRC32} = Compress::Raw::Zlib::crc32($$in, $self->{CRC32})
|
||||
if $self->{wantCRC32};
|
||||
|
||||
$self->{ADLER32} = Compress::Zlib::adler32($$in, $self->{ADLER32})
|
||||
if $self->{wantADLER32};
|
||||
}
|
||||
|
||||
${ $_[1] } .= $$in;
|
||||
$$in = $remainder;
|
||||
}
|
||||
|
||||
return STATUS_ENDSTREAM if $eof;
|
||||
return STATUS_OK ;
|
||||
}
|
||||
|
||||
sub reset
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
$self->{CompSize}->reset();
|
||||
$self->{UnCompSize} = 0;
|
||||
$self->{CRC32} = Compress::Raw::Zlib::crc32('');
|
||||
$self->{ADLER32} = Compress::Raw::Zlib::adler32('');
|
||||
|
||||
return STATUS_OK ;
|
||||
}
|
||||
|
||||
#sub count
|
||||
#{
|
||||
# my $self = shift ;
|
||||
# return $self->{UnCompSize} ;
|
||||
#}
|
||||
|
||||
sub compressedBytes
|
||||
{
|
||||
my $self = shift ;
|
||||
return $self->{CompSize} ;
|
||||
}
|
||||
|
||||
sub uncompressedBytes
|
||||
{
|
||||
my $self = shift ;
|
||||
return $self->{CompSize} ;
|
||||
}
|
||||
|
||||
sub sync
|
||||
{
|
||||
return STATUS_OK ;
|
||||
}
|
||||
|
||||
sub crc32
|
||||
{
|
||||
my $self = shift ;
|
||||
return $self->{CRC32};
|
||||
}
|
||||
|
||||
sub adler32
|
||||
{
|
||||
my $self = shift ;
|
||||
return $self->{ADLER32};
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
156
database/perl/lib/IO/Uncompress/Adapter/Inflate.pm
Normal file
156
database/perl/lib/IO/Uncompress/Adapter/Inflate.pm
Normal file
@@ -0,0 +1,156 @@
|
||||
package IO::Uncompress::Adapter::Inflate;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use bytes;
|
||||
|
||||
use IO::Compress::Base::Common 2.100 qw(:Status);
|
||||
use Compress::Raw::Zlib 2.100 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS);
|
||||
|
||||
our ($VERSION);
|
||||
$VERSION = '2.100';
|
||||
|
||||
|
||||
|
||||
sub mkUncompObject
|
||||
{
|
||||
my $crc32 = shift || 1;
|
||||
my $adler32 = shift || 1;
|
||||
my $scan = shift || 0;
|
||||
|
||||
my $inflate ;
|
||||
my $status ;
|
||||
|
||||
if ($scan)
|
||||
{
|
||||
($inflate, $status) = Compress::Raw::Zlib::InflateScan->new(
|
||||
#LimitOutput => 1,
|
||||
CRC32 => $crc32,
|
||||
ADLER32 => $adler32,
|
||||
WindowBits => - MAX_WBITS );
|
||||
}
|
||||
else
|
||||
{
|
||||
($inflate, $status) = Compress::Raw::Zlib::Inflate->new(
|
||||
AppendOutput => 1,
|
||||
LimitOutput => 1,
|
||||
CRC32 => $crc32,
|
||||
ADLER32 => $adler32,
|
||||
WindowBits => - MAX_WBITS );
|
||||
}
|
||||
|
||||
return (undef, "Could not create Inflation object: $status", $status)
|
||||
if $status != Z_OK ;
|
||||
|
||||
return bless {'Inf' => $inflate,
|
||||
'CompSize' => 0,
|
||||
'UnCompSize' => 0,
|
||||
'Error' => '',
|
||||
'ConsumesInput' => 1,
|
||||
} ;
|
||||
|
||||
}
|
||||
|
||||
sub uncompr
|
||||
{
|
||||
my $self = shift ;
|
||||
my $from = shift ;
|
||||
my $to = shift ;
|
||||
my $eof = shift ;
|
||||
|
||||
my $inf = $self->{Inf};
|
||||
|
||||
my $status = $inf->inflate($from, $to, $eof);
|
||||
$self->{ErrorNo} = $status;
|
||||
if ($status != Z_OK && $status != Z_STREAM_END && $status != Z_BUF_ERROR)
|
||||
{
|
||||
$self->{Error} = "Inflation Error: $status";
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
return STATUS_OK if $status == Z_BUF_ERROR ; # ???
|
||||
return STATUS_OK if $status == Z_OK ;
|
||||
return STATUS_ENDSTREAM if $status == Z_STREAM_END ;
|
||||
return STATUS_ERROR ;
|
||||
}
|
||||
|
||||
sub reset
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->inflateReset();
|
||||
|
||||
return STATUS_OK ;
|
||||
}
|
||||
|
||||
#sub count
|
||||
#{
|
||||
# my $self = shift ;
|
||||
# $self->{Inf}->inflateCount();
|
||||
#}
|
||||
|
||||
sub crc32
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->crc32();
|
||||
}
|
||||
|
||||
sub compressedBytes
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->compressedBytes();
|
||||
}
|
||||
|
||||
sub uncompressedBytes
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->uncompressedBytes();
|
||||
}
|
||||
|
||||
sub adler32
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->adler32();
|
||||
}
|
||||
|
||||
sub sync
|
||||
{
|
||||
my $self = shift ;
|
||||
( $self->{Inf}->inflateSync(@_) == Z_OK)
|
||||
? STATUS_OK
|
||||
: STATUS_ERROR ;
|
||||
}
|
||||
|
||||
|
||||
sub getLastBlockOffset
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->getLastBlockOffset();
|
||||
}
|
||||
|
||||
sub getEndOffset
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->getEndOffset();
|
||||
}
|
||||
|
||||
sub resetLastBlockByte
|
||||
{
|
||||
my $self = shift ;
|
||||
$self->{Inf}->resetLastBlockByte(@_);
|
||||
}
|
||||
|
||||
sub createDeflateStream
|
||||
{
|
||||
my $self = shift ;
|
||||
my $deflate = $self->{Inf}->createDeflateStream(@_);
|
||||
return bless {'Def' => $deflate,
|
||||
'CompSize' => 0,
|
||||
'UnCompSize' => 0,
|
||||
'Error' => '',
|
||||
}, 'IO::Compress::Adapter::Deflate';
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
__END__
|
||||
Reference in New Issue
Block a user