perl的Compress-Zlib奇怪的行为?

我一直在为这个疯狂…

我一直在collectl工具中使用gzflush()函数多年,最近在debian上发现了一些非常不寻常的东西。 实际上,我认为这是更新版本的Zlib。

这个问题似乎是function在某个地方改变了,虽然我可以在多个版本中编写代码,但是我首先会问问他人是否自己看到了这些信息,或者知道事实究竟发生了什么。

具体来说,如果我创build2个压缩文件,并立即gzflush与值2,这相当于Z_SYNC_FLUSH,它工作正常。 但是如果我再尝试刷新它们,至less在运行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,所以从开头的print语句中删除它:

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

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