使用 zipfile 提取大文件 [英] Extracting large files with zipfile

查看:42
本文介绍了使用 zipfile 提取大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 zipFile 库提取 1.23 GB 的 zip 文件.但它给出了以下错误:

I'm trying to extract a zip file of 1.23 GB with zipFile library. But it gives the following error:

 compression type 9 (deflate64)

这是我的代码:

zip_ref = zipfile.ZipFile(filepath, 'r')
zip_ref.extractall(newPath)

尝试提取内容时出错.

有没有办法用 Python 解压大的 zip 文件?

Is there any way to unzip large zip files with Python?

推荐答案

出现这种情况是因为 zipfile 模块中没有实现该压缩方法.

This happens because that compression method is not implemented in the zipfile module.

关于这个问题的一些讨论在这里:https://bugs.python.org/issue14313

Some discussion about the issue is here: https://bugs.python.org/issue14313

修复方法是引发 NotImplementedError 而不是添加对压缩方法的支持.

The fix was to raise a NotImplementedError instead of adding support for the compression method.

建议的解决方案:

  • 如果可能,请使用标准的 deflate 方法重新压缩文件.
  • 使用 subprocess 模块调用系统 unzip 命令,假设它已安装在您的操作系统上(如果它支持该压缩方法,老实说我不确定.我知道 7-zip 支持该方法.).
  • If possible, recompress the file using a standard deflate method.
  • Use the subprocess module to invoke the system unzip command, asssuming it is installed on your OS (if it supports that compression method, I'm honestly not sure. I know that 7-zip supports the method.).

这篇关于使用 zipfile 提取大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆