Simplified the code to open files with the compression I/O in the test suite helper.

This commit is contained in:
依瑪貓 2022-03-19 09:41:43 +08:00
parent 8f20c52412
commit 980409b142

View File

@ -229,10 +229,9 @@ sub read_file($) {
if ($file =~ /\.gz$/) { if ($file =~ /\.gz$/) {
# IO::Uncompress::Gunzip # IO::Uncompress::Gunzip
if (eval { require IO::Uncompress::Gunzip; 1; }) { if (eval { require IO::Uncompress::Gunzip; 1; }) {
my ($FH, $gz); my $gz;
$content = ""; $content = "";
open $FH, $file or die this_file . ": $file: $!"; $gz = IO::Uncompress::Gunzip->new($file)
$gz = IO::Uncompress::Gunzip->new($FH)
or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError"; or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError";
$content = join "", <$gz>; $content = join "", <$gz>;
$gz->close or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError"; $gz->close or die this_file . ": $file: $IO::Uncompress::Gunzip::GunzipError";
@ -253,10 +252,9 @@ sub read_file($) {
} elsif ($file =~ /\.bz2$/) { } elsif ($file =~ /\.bz2$/) {
# IO::Uncompress::Bunzip2 # IO::Uncompress::Bunzip2
if (eval { require IO::Uncompress::Bunzip2; 1; }) { if (eval { require IO::Uncompress::Bunzip2; 1; }) {
my ($FH, $bz); my $bz;
$content = ""; $content = "";
open $FH, $file or die this_file . ": $file: $!"; $bz = IO::Uncompress::Bunzip2->new($file)
$bz = IO::Uncompress::Bunzip2->new($FH)
or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error"; or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
$content = join "", <$bz>; $content = join "", <$bz>;
$bz->close or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error"; $bz->close or die this_file . ": $file: $IO::Uncompress::Bunzip2::Bunzip2Error";
@ -277,10 +275,9 @@ sub read_file($) {
} elsif ($file =~ /\.xz$/) { } elsif ($file =~ /\.xz$/) {
# IO::Uncompress::UnXz # IO::Uncompress::UnXz
if (eval { require IO::Uncompress::UnXz; 1; }) { if (eval { require IO::Uncompress::UnXz; 1; }) {
my ($FH, $xz); my $xz;
$content = ""; $content = "";
open $FH, $file or die this_file . ": $file: $!"; $xz = IO::Uncompress::UnXz->new($file)
$xz = IO::Uncompress::UnXz->new($FH)
or die this_file . ": $file: $IO::Uncompress::UnXz::UnXzError"; or die this_file . ": $file: $IO::Uncompress::UnXz::UnXzError";
$content = join "", <$xz>; $content = join "", <$xz>;
$xz->close or die this_file . ": $file: $IO::Uncompress::UnXz::UnXzError"; $xz->close or die this_file . ": $file: $IO::Uncompress::UnXz::UnXzError";
@ -335,9 +332,8 @@ sub write_file($$) {
if ($file =~ /\.gz$/) { if ($file =~ /\.gz$/) {
# IO::Compress::Gzip # IO::Compress::Gzip
if (eval { require IO::Compress::Gzip; 1; }) { if (eval { require IO::Compress::Gzip; 1; }) {
my ($FH, $gz); my $gz;
open $FH, ">$file" or die this_file . ": $file: $!"; $gz = IO::Compress::Gzip->new($file)
$gz = IO::Compress::Gzip->new($FH)
or die this_file . ": $file: $IO::Compress::Gzip::GzipError"; or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
($gz->write($content) == length $content) ($gz->write($content) == length $content)
or die this_file . ": $file: $IO::Compress::Gzip::GzipError"; or die this_file . ": $file: $IO::Compress::Gzip::GzipError";
@ -359,9 +355,8 @@ sub write_file($$) {
} elsif ($file =~ /\.bz2$/) { } elsif ($file =~ /\.bz2$/) {
# IO::Compress::Bzip2 # IO::Compress::Bzip2
if (eval { require IO::Compress::Bzip2; 1; }) { if (eval { require IO::Compress::Bzip2; 1; }) {
my ($FH, $bz); my $bz;
open $FH, ">$file" or die this_file . ": $file: $!"; $bz = IO::Compress::Bzip2->new($file)
$bz = IO::Compress::Bzip2->new($FH)
or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error"; or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
($bz->write($content) == length $content) ($bz->write($content) == length $content)
or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error"; or die this_file . ": $file: $IO::Compress::Bzip2::Bzip2Error";
@ -383,9 +378,8 @@ sub write_file($$) {
} elsif ($file =~ /\.xz/) { } elsif ($file =~ /\.xz/) {
# IO::Compress::Xz # IO::Compress::Xz
if (eval { require IO::Compress::Xz; 1; }) { if (eval { require IO::Compress::Xz; 1; }) {
my ($FH, $xz); my $xz;
open $FH, ">$file" or die this_file . ": $file: $!"; $xz = IO::Compress::Xz->new($file)
$xz = IO::Compress::Xz->new($FH)
or die this_file . ": $file: $IO::Compress::Xz::XzError"; or die this_file . ": $file: $IO::Compress::Xz::XzError";
($xz->write($content) == length $content) ($xz->write($content) == length $content)
or die this_file . ": $file: $IO::Compress::Xz::XzError"; or die this_file . ": $file: $IO::Compress::Xz::XzError";