Replaced Compress::Zlib with IO::Compress::Gzip and IO::Uncompress::Gunzip. Replaced Compress::Bzip2 with IO::Compress::Bzip2 and IO::Uncompress::Bunzip2.

This commit is contained in:
依瑪貓 2022-03-19 21:34:23 +08:00
parent 67dca3926a
commit effc9b8657
6 changed files with 141 additions and 168 deletions

View File

@ -61,8 +61,8 @@ my $build = Module::Build->new(
},
recommends => {
"File::MMagic" => 0,
"Compress::Zlib" => 0,
"Compress::Bzip2" => 2,
"IO::Compress::Gzip" => 0,
"IO::Compress::Bzip2" => 0,
"IO::Compress::Xz" => 0,
"Term::ReadKey" => 0,
},

View File

@ -2,6 +2,10 @@ reslog change log
2022-03-19
1. Added support for the xz compression.
2. Replaced Compress::Zlib with IO::Compress::Gzip and
IO::Uncompress::Gunzip.
3. Replaced Compress::Bzip2 with IO::Compress::Bzip2 and
IO::Uncompress::Bunzip2.
2020-02-06 version 3.17
1. Replaced the messy GNU-styled, multi-lingual documents with a

View File

@ -52,8 +52,8 @@ EOT
our (%OPT_PREREQ);
%OPT_PREREQ = (
"File::MMagic" => 0,
"Compress::Zlib" => 0,
"Compress::Bzip2" => 2,
"IO::Compress::Gzip" => 0,
"IO::Compress::Bzip2" => 0,
"IO::Compress::Xz" => 0,
"Term::ReadKey" => 0,
);

View File

@ -97,22 +97,23 @@ System Requirement
the [GnuWin32] home page. Be sure to save it as `file.exe`
somewhere in your `PATH`.
* [Compress::Zlib]
* [IO::Compress::Gzip] and [IO::Uncompress::Gunzip]
This is used to support reading/writing the gzip compressed
They are used to support reading/writing the gzip compressed
files. It is only needed when gzip compressed files are
encountered. If it is not available, `arclog` tries the `gzip`
executable instead. If that is not available, too, `arclog`
fails. You should not worry about Compress::Zlib since it comes
with Perl since version 5.9.3. If not, it is contained in the
[IO-Compress] distribution. You can download and install it from
the CPAN archive, or install it with the CPAN shell:
encountered. If they are not available, `arclog` tries the
`gzip` executable instead. If that is not available, too,
`arclog` fails. You should not worry about IO::Compress::Gzip
since it comes with Perl since version 5.9.3. If not, it is
contained in the [IO-Compress] distribution. You can download
and install it from the CPAN archive, or install it with the
CPAN shell:
cpan Compress::Zlib
cpan IO::Compress::Gzip
or with the CPANPLUS shell:
cpanp i Compress::Zlib
cpanp i IO::Compress::Gzip
For Debian/Ubuntu:
@ -134,38 +135,39 @@ System Requirement
[the gzip website]. Be sure to save it as `gzip.exe` somewhere
in your `PATH`.
* [Compress::Bzip2] version 2 or above.
* [IO::Compress::Bzip2] and [IO::Uncompress::Bunzip2]
This is used to support reading/writing the bzip2 compressed
files. It is only needed when bzip2 compressed files are
encountered. If it is not available, `reslog` tries the `bzip2`
executable instead. If that is not available, too, `reslog`
fails. Notice that older versions before 2 does not work, since
the file I/O compression was not implemented yet. You can
download and install Compress::Bzip2 from the CPAN archive, or
install it with the CPAN shell:
They are used to support reading/writing the bzip2 compressed
files. They are only needed when bzip2 compressed files are
encountered. If they are not available, `arclog` tries the
`bzip2` executable instead. If that is not available, too,
`arclog` fails. You should not worry about IO::Compress::Bzip2
since it comes with Perl since version 5.10.1. If not, it is
contained in the [IO-Compress] distribution. You can download
and install it from the CPAN archive, or install it with the
CPAN shell:
cpan Compress::Bzip2
cpan IO::Compress::Bzip2
or with the CPANPLUS shell:
cpanp i Compress::Bzip2
cpanp i IO::Compress::Bzip2
For Debian/Ubuntu:
sudo apt install libcompress-bzip2-perl
sudo apt install libio-compress-perl
For Red Hat/Fedora/CentOS:
sudo yum install perl-Compress-Bzip2
sudo yum install perl-IO-Compress
For FreeBSD:
ports install p5-Compress-Bzip2
ports install p5-IO-Compress
For ActivePerl:
ppm install Compress-Bzip2
ppm install IO-Compress
The alternative `bzip2.exe` for MS-Windows can be obtained from
[the bzip2 website]. Be sure to save it as `bzip2.exe` somewhere
@ -242,10 +244,12 @@ System Requirement
[ActivePerl]: https://www.activestate.com/products/perl/
[File::MMagic]: https://metacpan.org/pod/File::MMagic
[GnuWin32]: http://gnuwin32.sourceforge.net
[Compress::Zlib]: https://metacpan.org/pod/Compress::Zlib
[IO::Compress::Gzip]: https://metacpan.org/pod/IO::Compress::Gzip
[IO::Uncompress::Gunzip]: https://metacpan.org/pod/IO::Uncompress::Gunzip
[the gzip website]: https://www.gzip.org
[IO-Compress]: https://metacpan.org/release/IO-Compress
[Compress::Bzip2]: https://metacpan.org/pod/Compress::Bzip2
[IO-Compress]: https://metacpan.org/dist/IO-Compress
[IO::Compress::Bzip2]: https://metacpan.org/pod/IO::Compress::Bzip2
[IO::Uncompress::Bunzip2]: https://metacpan.org/pod/IO::Uncompress::Bunzip2
[the bzip2 website]: http://www.bzip.org
[IO::Compress::Xz]: https://metacpan.org/pod/IO::Compress::Xz
[IO::Uncompress::UnXz]: https://metacpan.org/pod/IO::Uncompress::UnXz

146
reslog
View File

@ -563,7 +563,6 @@ sub check_type : method {
# Check by file name suffix
# Check by file name suffix on empty files, too.
# Compress::Bzip2 2 creates empty files that confuses further processing.
if (-z $FH || $MAGIC_METHOD eq MAGIC_SUFFIX) {
return TYPE_GZIP if $file =~ /\.gz$/;
return TYPE_BZIP2 if $file =~ /\.bz2$/;
@ -847,13 +846,13 @@ sub check_gzip : method {
# Checked before
return ref($GZIP_IO)->new if defined $GZIP_IO;
# See whether Compress::Zlib or gzip
# See whether IO::Compress::Gzip or gzip
print STDERR "Checking gzip I/O handler to use ... " if $VERBOSE > 1;
print STDERR "\n Checking Compress::Zlib ... " if $VERBOSE > 2;
# Check if we have Compress::Zlib
if (eval { require Compress::Zlib; 1; }) {
print STDERR "\n Checking IO::Compress::Gzip ... " if $VERBOSE > 2;
# Check if we have IO::Compress::Gzip
if (eval { require IO::Compress::Gzip; require IO::Uncompress::Gunzip; 1; }) {
print STDERR "OK\nfound " if $VERBOSE > 2;
print STDERR "Compress::Zlib\n" if $VERBOSE > 1;
print STDERR "IO::Compress::Gzip\n" if $VERBOSE > 1;
return ($GZIP_IO = _private::IO::Gzip::PM->new);
}
# Not found
@ -872,7 +871,7 @@ sub check_gzip : method {
print STDERR "no\n" if $VERBOSE > 2;
print STDERR "not found\n" if $VERBOSE > 1;
die "$THIS_FILE: Necessary Compress::Zlib or gzip not available.\n$SHORT_HELP\n";
die "$THIS_FILE: Necessary IO::Compress::Gzip or gzip not available.\n$SHORT_HELP\n";
}
# Check for compression method of bzip2
@ -882,13 +881,13 @@ sub check_bzip2 : method {
# Checked before
return ref($BZIP2_IO)->new if defined $BZIP2_IO;
# See whether Compress::Bzip2 or bzip2
# See whether IO::Compress::Bzip2 or bzip2
print STDERR "Checking bzip2 I/O handler to use ... " if $VERBOSE > 1;
print STDERR "\n Checking Compress::Bzip2 ... " if $VERBOSE > 2;
# Check if we have Compress::Bzip2
if (eval { require Compress::Bzip2; import Compress::Bzip2 2.00; 1; }) {
print STDERR "\n Checking IO::Compress::Bzip2 ... " if $VERBOSE > 2;
# Check if we have IO::Compress::Bzip2
if (eval { require IO::Compress::Bzip2; require IO::Uncompress::Bunzip2; 1; }) {
print STDERR "OK\nfound " if $VERBOSE > 2;
print STDERR "Compress::Bzip2\n" if $VERBOSE > 1;
print STDERR "IO::Compress::Bzip2\n" if $VERBOSE > 1;
return ($BZIP2_IO = _private::IO::Bzip2::PM->new);
}
# Not found
@ -907,7 +906,7 @@ sub check_bzip2 : method {
print STDERR "no\n" if $VERBOSE > 2;
print STDERR "not found\n" if $VERBOSE > 1;
die "$THIS_FILE: Necessary Compress::Bzip2 or bzip2 not available.\n$SHORT_HELP\n";
die "$THIS_FILE: Necessary IO::Compress::Bzip2 or bzip2 not available.\n$SHORT_HELP\n";
}
# Check for compression method of xz
@ -1060,7 +1059,7 @@ sub close : method {
}
# _private::IO::Gzip::PM: The gzip module compression I/O handle
# _private::IO::Gzip::PM: The gzip module compression I/O handler
package _private::IO::Gzip::PM;
use 5.008;
use strict;
@ -1087,9 +1086,9 @@ sub open_read : method {
print STDERR "done\n" if $VERBOSE > 2;
}
($self->{"file"}, $self->{"FH"}) = ($file, $FH);
import Compress::Zlib qw(gzopen);
print STDERR " Attaching file with gzopen(..., \"rb\") ... " if $VERBOSE > 2;
$self->{"gz"} = gzopen($FH, "rb") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Uncompress::Gunzip ... " if $VERBOSE > 2;
$self->{"gz"} = IO::Uncompress::Gunzip->new($FH)
or die "$THIS_FILE: $file: $IO::Uncompress::Gunzip::GunzipError";
print STDERR "done\n" if $VERBOSE > 2;
return;
}
@ -1108,9 +1107,9 @@ sub open_write : method {
print STDERR "done\n" if $VERBOSE > 2;
}
($self->{"file"}, $self->{"FH"}) = ($file, $FH);
import Compress::Zlib qw(gzopen);
print STDERR " Attaching file with gzopen(..., \"wb9\") ... " if $VERBOSE > 2;
$self->{"gz"} = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Compress::Gzip ... " if $VERBOSE > 2;
$self->{"gz"} = IO::Compress::Gzip->new($FH, -Level => 9)
or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
print STDERR "done\n" if $VERBOSE > 2;
return;
}
@ -1129,7 +1128,6 @@ sub open_append : method {
print STDERR "done\n" if $VERBOSE > 2;
}
($self->{"file"}, $self->{"FH"}) = ($file, $FH);
import Compress::Zlib qw(gzopen);
# Save the original data if file has content so that file size is
# greater than 0. STDOUT is always of size 0.
@ -1150,18 +1148,20 @@ sub open_append : method {
print STDERR "done\n" if $VERBOSE > 2;
# Decompress the buffer and save to our file
print STDERR " Attaching buffer with gzopen(..., \"rb\") ... " if $VERBOSE > 2;
$gzt = gzopen($FHT, "rb") or die "$THIS_FILE: tempfile: $!";
print STDERR " Attaching buffer with IO::Uncompress::Gunzip ... " if $VERBOSE > 2;
$gzt = IO::Uncompress::Gunzip->new($FHT)
or die "$THIS_FILE: tempfile: $IO::Uncompress::Gunzip::GunzipError";
print STDERR "done\n" if $VERBOSE > 2;
print STDERR " Attaching file with gzopen(..., \"wb9\") ... " if $VERBOSE > 2;
$gz = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Compress::Gzip ... " if $VERBOSE > 2;
$gz = IO::Compress::Gzip->new($FH, -Level => 9)
or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
print STDERR "done\n" if $VERBOSE > 2;
print STDERR " Reading old records back from the buffer ... " if $VERBOSE > 2;
$count = 0;
while (($n = $gzt->gzreadline($_)) != 0) {
die "$THIS_FILE: tempfile: " . $gz->gzerror if $n == -1;
($gz->gzwrite($_) == $n) or die "$THIS_FILE: $file: " . $gz->gzerror;
while (defined($_ = $gzt->getline)) {
($gz->write($_) == length $_)
or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
$count++;
}
close $FHT or die "$THIS_FILE: tempfile: $!";
@ -1169,8 +1169,9 @@ sub open_append : method {
# A whole new file
} else {
print STDERR " Attaching file with gzopen(..., \"wb9\") ... " if $VERBOSE > 2;
$gz = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Compress::Gzip ... " if $VERBOSE > 2;
$gz = IO::Compress::Gzip->new($FH, -Level => 9)
or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
print STDERR "done\n" if $VERBOSE > 2;
}
@ -1179,15 +1180,7 @@ sub open_append : method {
}
# Read a line from the I/O stream
sub readline : method {
local ($_, %_);
my ($self, $file, $gz, $n);
$self = $_[0];
($file, $gz) = ($self->{"file"}, $self->{"gz"});
(($n = $gz->gzreadline($_)) != -1) or die "$THIS_FILE: $file: " . $gz->gzerror;
return undef if $n == 0;
return $_;
}
sub readline : method { $_[0]->{"gz"}->getline; }
# Output data to the I/O stream
sub write : method {
@ -1195,7 +1188,7 @@ sub write : method {
my ($self, $file, $gz);
($self, $_) = @_;
($file, $gz) = ($self->{"file"}, $self->{"gz"});
($gz->gzwrite($_) == length $_) or die "$THIS_FILE: $file: " . $gz->gzerror;
($gz->write($_) == length $_) or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
return;
}
@ -1217,15 +1210,16 @@ sub close : method {
# Create empty compressed content
print STDERR " Applying empty compressed content ... " if $VERBOSE > 2;
$_ = gzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
$_->gzclose and die "$THIS_FILE: $file: " . $_->gzerror;
$_ = IO::Compress::Gzip->new($FH, -Level => 9)
or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
$_->close or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
undef $_;
undef $gz;
print STDERR "done\n" if $VERBOSE > 2;
}
if (defined $gz) {
$gz->gzclose and die "$THIS_FILE: $file: " . $gz->gzerror;
$gz->close or die "$THIS_FILE: $file: $IO::Compress::Gzip::GzipError";
}
CORE::close $self->{"FH"} if $self->{"FH"}->opened;
delete $self->{"gz"};
@ -1514,7 +1508,7 @@ sub close : method {
}
# _private::IO::Bzip2::PM: The bzip2 module compression I/O handle
# _private::IO::Bzip2::PM: The bzip2 module compression I/O handler
package _private::IO::Bzip2::PM;
use 5.008;
use strict;
@ -1541,9 +1535,9 @@ sub open_read : method {
print STDERR "done\n" if $VERBOSE > 2;
}
($self->{"file"}, $self->{"FH"}) = ($file, $FH);
import Compress::Bzip2 qw(bzopen);
print STDERR " Attaching file with bzopen(..., \"rb\") ... " if $VERBOSE > 2;
$self->{"bz"} = bzopen($FH, "rb") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Uncompress::Bunzip2 ... " if $VERBOSE > 2;
$self->{"bz"} = IO::Uncompress::Bunzip2->new($FH)
or die "$THIS_FILE: $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
print STDERR "done\n" if $VERBOSE > 2;
return;
}
@ -1562,9 +1556,9 @@ sub open_write : method {
print STDERR "done\n" if $VERBOSE > 2;
}
($self->{"file"}, $self->{"FH"}) = ($file, $FH);
import Compress::Bzip2 qw(bzopen);
print STDERR " Attaching file with bzopen(..., \"wb9\") ... " if $VERBOSE > 2;
$self->{"bz"} = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Compress::Bzip2 ... " if $VERBOSE > 2;
$self->{"bz"} = IO::Compress::Bzip2->new($FH, BlockSize100K => 9)
or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
print STDERR "done\n" if $VERBOSE > 2;
return;
}
@ -1583,7 +1577,6 @@ sub open_append : method {
print STDERR "done\n" if $VERBOSE > 2;
}
($self->{"file"}, $self->{"FH"}) = ($file, $FH);
import Compress::Bzip2 qw(bzopen);
# Save the original data if file has content so that file size is
# greater than 0. STDOUT is always of size 0.
@ -1604,19 +1597,20 @@ sub open_append : method {
print STDERR "done\n" if $VERBOSE > 2;
# Decompress the buffer and save to our file
print STDERR " Attaching buffer with bzopen(..., \"rb\") ... " if $VERBOSE > 2;
$bzt = bzopen($FHT, "rb") or die "$THIS_FILE: tempfile: $!";
print STDERR " Attaching buffer with IO::Uncompress::Bunzip2 ... " if $VERBOSE > 2;
$bzt = IO::Uncompress::Bunzip2->new($FHT)
or die "$THIS_FILE: $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
print STDERR "done\n" if $VERBOSE > 2;
print STDERR " Attaching file with bzopen(..., \"wb9\") ... " if $VERBOSE > 2;
$bz = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Compress::Bzip2 ... " if $VERBOSE > 2;
$bz = IO::Compress::Bzip2->new($FH, BlockSize100K => 9)
or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
print STDERR "done\n" if $VERBOSE > 2;
print STDERR " Reading old records back from the buffer ... " if $VERBOSE > 2;
$count = 0;
while (($n = $bzt->bzreadline($_)) != 0) {
die "$THIS_FILE: tempfile: " . $bz->bzerror if $n == -1;
($bz->bzwrite($_, length $_) == length $_)
or die "$THIS_FILE: $file: " . $bz->bzerror;
while (defined($_ = $bzt->getline)) {
($bz->write($_) == length $_)
or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
$count++;
}
close $FHT or die "$THIS_FILE: tempfile: $!";
@ -1624,8 +1618,9 @@ sub open_append : method {
# A whole new file
} else {
print STDERR " Attaching file with bzopen(..., \"wb9\") ... " if $VERBOSE > 2;
$bz = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
print STDERR " Attaching file with IO::Compress::Bzip2 ... " if $VERBOSE > 2;
$bz = IO::Compress::Bzip2->new($FH, BlockSize100K => 9)
or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
print STDERR "done\n" if $VERBOSE > 2;
}
@ -1634,15 +1629,7 @@ sub open_append : method {
}
# Read a line from the I/O stream
sub readline : method {
local ($_, %_);
my ($self, $file, $bz, $n);
$self = $_[0];
($file, $bz) = ($self->{"file"}, $self->{"bz"});
(($n = $bz->bzreadline($_)) != -1) or die "$THIS_FILE: $file: " . $bz->bzerror;
return undef if $n == 0;
return $_;
}
sub readline : method { $_[0]->{"bz"}->getline; }
# Output data to the I/O stream
sub write : method {
@ -1650,8 +1637,7 @@ sub write : method {
my ($self, $file, $bz);
($self, $_) = @_;
($file, $bz) = ($self->{"file"}, $self->{"bz"});
($bz->bzwrite($_, length $_) == length $_)
or die "$THIS_FILE: $file: " . $bz->bzerror;
($bz->write($_) == length $_) or die "$THIS_FILE: $file: $IO::Compress::Xz::XzError";
return;
}
@ -1673,15 +1659,16 @@ sub close : method {
# Create empty compressed content
print STDERR " Applying empty compressed content ... " if $VERBOSE > 2;
$_ = bzopen($FH, "wb9") or die "$THIS_FILE: $file: $!";
$_->bzclose and die "$THIS_FILE: $file: " . $_->bzerror;
$_ = IO::Compress::Bzip2->new($FH, BlockSize100K => 9)
or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
$_->close or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
undef $_;
undef $bz;
print STDERR "done\n" if $VERBOSE > 2;
}
if (defined $bz) {
$bz->bzclose and die "$THIS_FILE: $file: " . $bz->bzerror;
$bz->close or die "$THIS_FILE: $file: $IO::Compress::Bzip2::Bzip2Error";
}
CORE::close $self->{"FH"} if $self->{"FH"}->opened;
delete $self->{"bz"};
@ -2922,11 +2909,12 @@ messages.
=head1 SEE ALSO
L<Compress::Zlib(3)>,
L<Compress::Bzip2(3)>,
L<gzip(1)|gzip/1>, L<IO::Compress::Gzip(3)|IO::Compress::Gzip/3>,
L<IO::Uncompress::Gunzip(3)|IO::Uncompress::Gunzip/3>,
L<bzip2(1)|bzip2/1>, L<IO::Compress::Bzip2(3)|IO::Compress::Bzip2/3>,
L<IO::Uncompress::Bunzip2(3)|IO::Uncompress::Bunzip2/3>,
L<xz(1)|xz/1>, L<IO::Compress::Xz(3)|IO::Compress::Xz/3>,
L<IO::Uncompress::UnXz(3)|IO::Uncompress::UnXz/3>,
L<perlthrtut(1)>, L<gzip(1)>, L<zlib(3)>,
L<bzip2(1)>.
L<perlthrtut(1)>.
=cut

View File

@ -186,22 +186,14 @@ sub read_file($) {
# a gzip compressed file
if ($file =~ /\.gz$/) {
# Compress::Zlib
if (eval { require Compress::Zlib;
Compress::Zlib->import(qw(gzopen));
1; }) {
use Compress::Zlib qw(gzopen);
my ($FH, $gz);
# IO::Uncompress::Gunzip
if (eval { require IO::Uncompress::Gunzip; 1; }) {
my $gz;
$content = "";
open $FH, $file or die this_file . ": $file: $!";
$gz = gzopen($FH, "rb") or die this_file . ": $file: $!";
while (1) {
($gz->gzread($_, 10240) != -1)
or die this_file . ": $file: " . $gz->gzerror;
$content .= $_;
last if length $_ < 10240;
}
$gz->gzclose and die this_file . ": $file: " . $gz->gzerror;
$gz = IO::Uncompress::Gunzip->new($file)
or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError";
$content = join "", <$gz>;
$gz->close or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError";
return $content;
# gzip executable
@ -217,22 +209,14 @@ sub read_file($) {
# a bzip compressed file
} elsif ($file =~ /\.bz2$/) {
# Compress::Bzip2
if (eval { require Compress::Bzip2;
Compress::Bzip2->import(2.00);
Compress::Bzip2->import(qw(bzopen));
1; }) {
my ($FH, $bz);
# IO::Uncompress::Bunzip2
if (eval { require IO::Uncompress::Bunzip2; 1; }) {
my $bz;
$content = "";
open $FH, $file or die this_file . ": $file: $!";
$bz = bzopen($FH, "rb") or die this_file . ": $file: $!";
while (1) {
($bz->bzread($_, 10240) != -1)
or die this_file . ": $file: " . $bz->bzerror;
$content .= $_;
last if length $_ < 10240;
}
$bz->bzclose and die this_file . ": $file: " . $bz->bzerror;
$bz = IO::Uncompress::Bunzip2->new($file)
or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
$content = join "", <$bz>;
$bz->close or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
return $content;
# bzip2 executable
@ -305,16 +289,14 @@ sub write_file($$) {
# a gzip compressed file
if ($file =~ /\.gz$/) {
# Compress::Zlib
if (eval { require Compress::Zlib;
Compress::Zlib->import(qw(gzopen));
1; }) {
my ($FH, $gz);
open $FH, ">$file" or die this_file . ": $file: $!";
$gz = gzopen($FH, "wb9") or die this_file . ": $file: $!";
($gz->gzwrite($content) == length $content)
or die this_file . ": $file: " . $gz->gzerror;
$gz->gzclose and die this_file . ": $file: " . $gz->gzerror;
# IO::Compress::Gzip
if (eval { require IO::Compress::Gzip; 1; }) {
my $gz;
$gz = IO::Compress::Gzip->new($file, -Level => 9)
or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
($gz->write($content) == length $content)
or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
$gz->close or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
return;
# gzip executable
@ -330,19 +312,14 @@ sub write_file($$) {
# a bzip compressed file
} elsif ($file =~ /\.bz2$/) {
# Compress::Bzip2
if (eval { require Compress::Bzip2;
Compress::Bzip2->import(2.00);
Compress::Bzip2->import(qw(bzopen));
1; }) {
my ($FH, $bz);
open $FH, ">$file" or die this_file . ": $file: $!";
$bz = bzopen($FH, "wb9") or die this_file . ": $file: $!";
if ($content ne "") {
($bz->bzwrite($content, length $content) == length $content)
or die this_file . ": $file: " . $bz->bzerror;
}
$bz->bzclose and die this_file . ": $file: " . $bz->bzerror;
# IO::Compress::Bzip2
if (eval { require IO::Compress::Bzip2; 1; }) {
my $bz;
$bz = IO::Compress::Bzip2->new($file, BlockSize100K => 9)
or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
($bz->write($content) == length $content)
or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
$bz->close or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
return;
# bzip2 executable
@ -554,18 +531,18 @@ sub has_no_file() {
# If we have gzip support somewhere
sub has_no_gzip() {
$HAS_NO_GZIP = eval { require Compress::Zlib; 1; }
$HAS_NO_GZIP = eval { require IO::Compress::Gzip; require IO::Uncompress::Gunzip; 1; }
|| defined where_is "gzip"?
0: "Compress::Zlib or gzip executable not available"
0: "IO::Compress::Gzip or gzip executable not available"
if !defined $HAS_NO_GZIP;
return $HAS_NO_GZIP;
}
# If we have bzip2 support somewhere
sub has_no_bzip2() {
$HAS_NO_BZIP2 = eval { require Compress::Bzip2; Compress::Bzip2->import(2.00); 1; }
$HAS_NO_BZIP2 = eval { require IO::Compress::Bzip2; require IO::Uncompress::Bunzip2; 1; }
|| defined where_is "bzip2"?
0: "Compress::Bzip2 v2 or bzip2 executable not available"
0: "IO::Compress::Bzip2 v2 or bzip2 executable not available"
if !defined $HAS_NO_BZIP2;
return $HAS_NO_BZIP2;
}