简体   繁体   English

可以将OS X gzip配置为匹配Java GZIPOutputStream吗?

[英]Can OS X gzip be configured to match Java GZIPOutputStream?

I'm trying to compare the output of running strings through GZIP on both Java, and the CLI gzip command. 我试图在Java和CLI gzip命令上通过GZIP比较运行字符串的输出。 The outputs are not the same, and I've figure out why, but not sure how to get them to jive with each other. 输出是不一样的,我已经找出原因,但不知道如何让他们彼此jive。

I've read a number of questions on SO, have read the man pages for gzip, and the code for both GZIPOutputStream and DeflaterOutputStream. 我已经阅读了很多关于SO的问题,已经阅读了gzip的手册页,以及GZIPOutputStream和DeflaterOutputStream的代码。 The default compression level for GZIPOutputStream (set through Deflator) is "-1", and there's little explanation as to what that means. GZIPOutputStream的默认压缩级别(通过Deflator设置)为“-1”,并且几乎没有解释这意味着什么。 Furthermore, gzip CLI only allows for values between 1 and 9, inclusive. 此外,gzip CLI仅允许1到9之间的值,包括1和9。

So is there a way I can change the compression settings in either Java or the gzip command to make them produce the same output? 那么有没有办法可以在Java或gzip命令中更改压缩设置以使它们产生相同的输出?

No. Java is using the zlib deflator, which is derived from but not exactly the same as the older gzip command-line utility deflator. 不,Java正在使用zlib平减器,它是从旧的gzip命令行实用程序平减器派生但不完全相同的。 They will generally not produce the same output and there are no settings to coerce them to do so. 它们通常不会产生相同的输出,也没有设置强制它们这样做。

Compression level -1 requests the default compression level, which in the current zlib implementation is level 6 . 压缩级别-1请求默认压缩级别,当前zlib实现中的级别为6级。

I would have to ask why you care to get their outputs to be the same. 我不得不问你为什么要关心他们的输出是一样的。 All that matters is that the compression is lossless, ie, that both the gzip and Java compressed streams produce the same original data when decompressed. 重要的是压缩是无损的,即gzip和Java压缩流在解压缩时产生相同的原始数据。 There is no requirement that, for example, different versions of zlib produce the same output at the same compression level. 例如,不要求不同版本的zlib在相同的压缩级别产生相同的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM