perl 的 Compress-Zlib 行为异常?

perl 的 Compress-Zlib 行为异常?

我快被这个搞疯了……

多年来,我一直在 collectl 工具中使用 gzflush() 函数,最近发现它在 debian 上有一些非常不寻常的地方。实际上,我认为这更多的是因为它是 Zlib 的一个较新版本。

问题似乎是功能在某个地方发生了变化,虽然我可以围绕多个版本进行编码,但我首先想问问其他人他们是否亲眼见过这种情况或是否知道究竟发生了什么。

具体来说,如果我创建 2 个压缩文件并立即使用值 2(相当于 Z_SYNC_FLUSH)对它们进行 gzflush,则运行正常。但是,如果我随后尝试第二次刷新它们,至少在运行 zlib V2.02 的 debian 上,它会失败。相同的代码在 rhel5.2 和 zlib V1.42 上运行正常。

只要我不尝试刷新已经刷新的文件,debian 版本似乎没问题,但我发现这非常烦人,想知道我是否做错了什么?

这是我的复制器:

#!/usr/bin/perl -w

use Compress::Zlib;

printf "%d %d %d %d %d\n", Z_FINISH, Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_BLOCK;

#require "Compress/Zlib.pm";

$aaa=Compress::Zlib::gzopen("/tmp/foo.gz", 'ab') or die "flush error";
$bbb=Compress::Zlib::gzopen("/tmp/foo.gz", 'ab') or die "flush error";

$m=2;
print "Flush AAA\n";
$aaa-> gzflush($m)<0 and error($aaa);
print "Flush BBB\n";
$bbb->gzflush($m)<0 and error($bbb);

print "Flush AAA\n";
$aaa-> gzflush($m)<0 and error($bbb);
print "Flush BBB\n";
$bbb->gzflush($m)<0 and error($bbb);

sub error
{ printf "Flush error reason: %s\n", $_[0]->gzerror(); $_[0]->gzclose(); exit; }

在 Debian 上运行这个我看到了:

./test.pl
4 0 2 3 5
Flush AAA
Flush BBB
Flush AAA
Flush error reason: buffer error

而我之前的 rhel 系统上的相同脚本却能做到这一点。我注意到符号 Z_BLOCK 在早期版本中没有定义,因此在开头从打印语句中删除了它:

./test.pl
4 0 2 3
Flush AAA
Flush BBB
Flush AAA
Flush BBB

答案1

只是为了让大家知道,我已经与 Compress::Zlib 的作者交换了电子邮件,他确认这是一个错误,他将在未来的版本中解决。-mark

相关内容