eaiovnaovbqoebvqoeavibavo Deflate.pm000064400000006110147635117770006466 0ustar00package IO::Compress::Adapter::Deflate ; use strict; use warnings; use bytes; use IO::Compress::Base::Common 2.061 qw(:Status); use Compress::Raw::Zlib 2.061 qw( !crc32 !adler32 ) ; require Exporter; our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS, @EXPORT, %DEFLATE_CONSTANTS); $VERSION = '2.061'; @ISA = qw(Exporter); @EXPORT_OK = @Compress::Raw::Zlib::DEFLATE_CONSTANTS; %EXPORT_TAGS = %Compress::Raw::Zlib::DEFLATE_CONSTANTS; @EXPORT = @EXPORT_OK; %DEFLATE_CONSTANTS = %EXPORT_TAGS ; sub mkCompObject { my $crc32 = shift ; my $adler32 = shift ; my $level = shift ; my $strategy = shift ; my ($def, $status) = new Compress::Raw::Zlib::Deflate -AppendOutput => 1, -CRC32 => $crc32, -ADLER32 => $adler32, -Level => $level, -Strategy => $strategy, -WindowBits => - MAX_WBITS; return (undef, "Cannot create Deflate object: $status", $status) if $status != Z_OK; return bless {'Def' => $def, 'Error' => '', } ; } sub compr { my $self = shift ; my $def = $self->{Def}; my $status = $def->deflate($_[0], $_[1]) ; $self->{ErrorNo} = $status; if ($status != Z_OK) { $self->{Error} = "Deflate Error: $status"; return STATUS_ERROR; } return STATUS_OK; } sub flush { my $self = shift ; my $def = $self->{Def}; my $opt = $_[1] || Z_FINISH; my $status = $def->flush($_[0], $opt); $self->{ErrorNo} = $status; if ($status != Z_OK) { $self->{Error} = "Deflate Error: $status"; return STATUS_ERROR; } return STATUS_OK; } sub close { my $self = shift ; my $def = $self->{Def}; $def->flush($_[0], Z_FINISH) if defined $def ; } sub reset { my $self = shift ; my $def = $self->{Def}; my $status = $def->deflateReset() ; $self->{ErrorNo} = $status; if ($status != Z_OK) { $self->{Error} = "Deflate Error: $status"; return STATUS_ERROR; } return STATUS_OK; } sub deflateParams { my $self = shift ; my $def = $self->{Def}; my $status = $def->deflateParams(@_); $self->{ErrorNo} = $status; if ($status != Z_OK) { $self->{Error} = "deflateParams Error: $status"; return STATUS_ERROR; } return STATUS_OK; } #sub total_out #{ # my $self = shift ; # $self->{Def}->total_out(); #} # #sub total_in #{ # my $self = shift ; # $self->{Def}->total_in(); #} sub compressedBytes { my $self = shift ; $self->{Def}->compressedBytes(); } sub uncompressedBytes { my $self = shift ; $self->{Def}->uncompressedBytes(); } sub crc32 { my $self = shift ; $self->{Def}->crc32(); } sub adler32 { my $self = shift ; $self->{Def}->adler32(); } 1; __END__ Identity.pm000064400000010747147635117770006726 0ustar00package IO::Uncompress::Adapter::Identity; use warnings; use strict; use bytes; use IO::Compress::Base::Common 2.061 qw(:Status); use IO::Compress::Zip::Constants ; our ($VERSION); $VERSION = '2.061'; use Compress::Raw::Zlib 2.061 (); sub mkUncompObject { my $streaming = shift; my $zip64 = shift; my $crc32 = 1; #shift ; my $adler32 = shift; bless { 'CompSize' => new U64 , # 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} = 0; $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__ Bzip2.pm000064400000005044147635117770006115 0ustar00package IO::Compress::Adapter::Bzip2 ; use strict; use warnings; use bytes; use IO::Compress::Base::Common 2.061 qw(:Status); use Compress::Raw::Bzip2 2.061 ; our ($VERSION); $VERSION = '2.061'; sub mkCompObject { my $BlockSize100K = shift ; my $WorkFactor = shift ; my $Verbosity = shift ; $BlockSize100K = 1 if ! defined $BlockSize100K ; $WorkFactor = 0 if ! defined $WorkFactor ; $Verbosity = 0 if ! defined $Verbosity ; my ($def, $status) = new Compress::Raw::Bzip2(1, $BlockSize100K, $WorkFactor, $Verbosity); return (undef, "Could not create Deflate object: $status", $status) if $status != BZ_OK ; return bless {'Def' => $def, 'Error' => '', 'ErrorNo' => 0, } ; } sub compr { my $self = shift ; my $def = $self->{Def}; my $status = $def->bzdeflate($_[0], $_[1]) ; $self->{ErrorNo} = $status; if ($status != BZ_RUN_OK) { $self->{Error} = "Deflate Error: $status"; return STATUS_ERROR; } return STATUS_OK; } sub flush { my $self = shift ; my $def = $self->{Def}; my $status = $def->bzflush($_[0]); $self->{ErrorNo} = $status; if ($status != BZ_RUN_OK) { $self->{Error} = "Deflate Error: $status"; return STATUS_ERROR; } return STATUS_OK; } sub close { my $self = shift ; my $def = $self->{Def}; my $status = $def->bzclose($_[0]); $self->{ErrorNo} = $status; if ($status != BZ_STREAM_END) { $self->{Error} = "Deflate Error: $status"; return STATUS_ERROR; } return STATUS_OK; } sub reset { my $self = shift ; my $outer = $self->{Outer}; my ($def, $status) = new Compress::Raw::Bzip2(); $self->{ErrorNo} = ($status == BZ_OK) ? 0 : $status ; if ($status != BZ_OK) { $self->{Error} = "Cannot create Deflate object: $status"; return STATUS_ERROR; } $self->{Def} = $def; return STATUS_OK; } sub compressedBytes { my $self = shift ; $self->{Def}->compressedBytes(); } sub uncompressedBytes { my $self = shift ; $self->{Def}->uncompressedBytes(); } #sub total_out #{ # my $self = shift ; # 0; #} # #sub total_in #{ # my $self = shift ; # $self->{Def}->total_in(); #} # #sub crc32 #{ # my $self = shift ; # $self->{Def}->crc32(); #} # #sub adler32 #{ # my $self = shift ; # $self->{Def}->adler32(); #} 1; __END__ Bunzip2.pm000064400000003772147635131420006452 0ustar00package IO::Uncompress::Adapter::Bunzip2; use strict; use warnings; use bytes; use IO::Compress::Base::Common 2.061 qw(:Status); use Compress::Raw::Bzip2 2.061 ; our ($VERSION, @ISA); $VERSION = '2.061'; sub mkUncompObject { my $small = shift || 0; my $verbosity = shift || 0; my ($inflate, $status) = new Compress::Raw::Bunzip2(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) = new Compress::Raw::Bunzip2(); $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__ Inflate.pm000064400000006320147635131420006473 0ustar00package IO::Uncompress::Adapter::Inflate; use strict; use warnings; #use bytes; use IO::Compress::Base::Common 2.061 qw(:Status); use Compress::Raw::Zlib 2.061 qw(Z_OK Z_BUF_ERROR Z_STREAM_END Z_FINISH MAX_WBITS); our ($VERSION); $VERSION = '2.061'; sub mkUncompObject { my $crc32 = shift || 1; my $adler32 = shift || 1; my $scan = shift || 0; my $inflate ; my $status ; if ($scan) { ($inflate, $status) = new Compress::Raw::Zlib::InflateScan #LimitOutput => 1, CRC32 => $crc32, ADLER32 => $adler32, WindowBits => - MAX_WBITS ; } else { ($inflate, $status) = new Compress::Raw::Zlib::Inflate 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__