1

DEFLATE 有十种不同的压缩级别(0 无压缩和最快,9 最佳压缩和最慢)。为原始 DEFLATE 数据确定此类级别的最佳方法是什么?

一种明显(但缓慢)的方法是尝试每种方法并按顺序进行比较。作为一个附带问题,是否可以保证文件的压缩数据大小从压缩级别 0 到 9 严格不增加?如果是这样,二分搜索可以将这个过程加快两倍/三倍。

4

2 回答 2

4

如果您只有压缩数据,则不包含此类信息。压缩级别只能针对压缩进行配置,因此不会在压缩数据中进行编码。

但是,如果您使用 zlib 之类的东西,它会添加包含压缩级别的标头。来自https://www.rfc-editor.org/rfc/rfc1950

  FLEVEL (Compression level)
     These flags are available for use by specific compression
     methods.  The "deflate" method (CM = 8) sets these flags as
     follows:

        0 - compressor used fastest algorithm
        1 - compressor used fast algorithm
        2 - compressor used default algorithm
        3 - compressor used maximum compression, slowest algorithm

     The information in FLEVEL is not needed for decompression; it
     is there to indicate if recompression might be worthwhile.

如果您不使用添加信息标头的库,您可以自己实现它(如果您的应用程序确实需要这样做)。只需在开头添加一两个字节(通常)即可。

于 2017-11-28T08:38:59.363 回答
3

除了缓慢的方法,没有。

不,不能保证压缩后的大小是单调的。然而,不单调是非常罕见的。

于 2013-04-22T20:56:05.333 回答