Python 在压缩大文件时使用 ZIP64 扩展名

标签 python zip zlib python-zipfile

我有一个压缩输出文件的脚本。问题是其中一个文件超过 4Gigs。如何将我的脚本转换为使用 ZIP64 扩展而不是标准 zip?

这是我目前压缩的方式:

try:
    import zlib
    compression = zipfile.ZIP_DEFLATED
except:
    compression = zipfile.ZIP_STORED

modes = { zipfile.ZIP_DEFLATED: 'deflated',
          zipfile.ZIP_STORED:   'stored',
          } 

compressed_name = 'edw_files_' + datetime.strftime(date(), '%Y%m%d') + '.zip' 
print 'creating archive'
zf = zipfile.ZipFile('edw_files_' + datetime.strftime(date(), '%Y%m%d') + '.zip', mode='w')
try:
    zf.write(name1, compress_type=compression)
    zf.write(name2, compress_type=compression)
    zf.write(name3, compress_type=compression)
finally:
    print 'closing'
    zf.close()

最佳答案

查看 zipfile-objects .

你可以这样做:

zf = zipfile.ZipFile('edw_files_' + datetime.strftime(date(), '%Y%m%d') + '.zip', mode='w', allowZip64 = True)

关于Python 在压缩大文件时使用 ZIP64 扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29830531/

相关文章:

python 3 : unsupported operand type(s) for +: 'float' and 'str'

c# - SharpZipLib 检查并选择 ZIP 文件的内容

c++ - 从 zlib.h 解压缩 - 错误 - 未定义对 `uncompress_gzip' 的引用

python - 如何在python中减去两个列表

warnings - zlib,苛刻的编译器警告和配置测试

c++ - 以字节为单位解压缩加密文件

python - 如何在 python 中查找/阅读有关方法和模块的文档?

python - 尝试从一组图像创建 GIF

python - Microsoft Teams Python Botbuilder 主动消息传递

javascript - 将 zip 文件返回到 angularjs 进行下载