Big file compression with python给出了一个很好的例子,说明如何使用例如bz2 纯粹用 Python 压缩一组非常大的文件(或大文件)。
pigz说你可以通过利用并行压缩来做得更好。 据我所知(和谷歌搜索),到目前为止,我找不到在纯 Python 代码中执行此操作的 Python 等价物。
是否有针对 pigz
或等价物的并行 Python 实现?
最佳答案
mgzip能够做到这一点
Using a block indexed GZIP file format to enable compress and decompress in parallel. This implement use 'FEXTRA' to record the index of compressed member, which is defined in offical GZIP file format specification version 4.3, so it is fully compatible with normal GZIP implementation.
import mgzip
num_cpus = 0 # will use all available CPUs
with open('original_file.txt', 'rb') as original, mgzip.open(
'gzipped_file.txt.gz', 'wb', thread=num_cpus, blocksize=2 * 10 ** 8
) as fw:
fw.write(original.read())
我能够在 72 个 CPU 的服务器上将压缩时间从 45 分钟加快到 5 分钟
关于python - 如何使用 Python 实现并行 gzip 压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42867930/