是否有任何 Python 压缩模块算法只是为了速度优化而存储数据?



来自维基百科,关于ZPAQ压缩-

ZPAQ 有 5 个压缩级别,从快速到最佳。除了最佳级别之外,它使用用于重复数据删除的 order-1 预测表的统计信息来测试输入是否随机。如果是这样,则作为速度优化,它将不压缩地存储。

我一直在使用 Python 数据压缩和归档模块,想知道这些实现(ZLIBBZ2LZMA(是否做同样的事情? 当数据看起来几乎是随机的时,他们中的任何一个是否只是"按原样"存储数据? 我不是编码专家,不能真正遵循源代码。


相关:如何有效地预测数据是否可压缩

一些不完整/最佳猜测的评论:

LZMA2似乎这样做了,尽管原因不同:压缩比;而不是为了提高压缩时间。

这在维基上指出:

  • LZMA2 is a simple container format that can include both uncompressed data and LZMA data, possibly with multiple different LZMA encoding parameters.
  • The XZ LZMA2 encoder processes the input in chunks (of up to 2 MB uncompressed size or 64 KB compressed size, whichever is lower), handing each chunk to the LZMA encoder, and then deciding whether to output an LZMA2 LZMA chunk including the encoded data, or to output an LZMA2 uncompressed chunk, depending on which is shorter (LZMA, like any other compressor, will necessarily expand rather than compress some kinds of data).

后一句话还表明,没有预期的压缩速度增益,因为它或多或少是一种:do both and pick best方法。

(这篇文章似乎专注于基于 xz 的 lzma2;可能会转移到 python 中的任何内容;但没有保证(

上面,连同python的文档:

Compression filters:
FILTER_LZMA1 (for use with FORMAT_ALONE)
FILTER_LZMA2 (for use with FORMAT_XZ and FORMAT_RAW)

会让我觉得你得到了你需要的一切,只需要使用正确的过滤器。

因此,请再次检查您的推理(时间或压缩比(,并使用自定义准备的混合数据尝试使用lzma2过滤器(如果您不想盲目信任(。

直觉我不希望更经典的 zlib/bz2 格式利用不可压缩的数据(但这纯粹是猜测(。

最新更新