python - 如何使用 Python 实现并行 gzip 压缩?

标签 python zlib

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/

相关文章:

Java 和 HttpUnit 存在 GZip 错误

python - 后台线程记录到 Flask 应用程序中的服务器发送事件流

python - 在管理中保存新模型时,在表 "django_admin_log"上插入或更新违反外键约束

c++ - 如何使用 boost iostreams 进行流式解压缩

node.js - 在 NodeJS 中使用 Zlib 压缩文件

java - 为什么我的未压缩 PNG 像素数据不准确?

python - 在 django 模板中解析和排序 csv 文件

python - Phantomjs 切换到错误的 iframe

python - 与使用 PyODBC 查询数据库的同事共享 Python .exe 时,是否只需要下载适用于 SQL Server 的 ODBC 驱动程序?

java - 无法使用 Apache MINA 压缩过滤器对通过 java.util.zip.Deflater 缩小的缓冲区进行充气