2

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)

Here's my code:

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

It gives error while trying to extract the contents.

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

Dharman
  • 30,962
  • 25
  • 85
  • 135
Tahreem Iqbal
  • 985
  • 6
  • 17
  • 43

2 Answers2

1

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

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

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

Suggested solutions:

  • 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.).
Krumelur
  • 31,081
  • 7
  • 77
  • 119
  • Let me get this straight. There's no way to fix this bug and the only solution is to recompress the file and use `unzip` command with `subprocess` module, which may or may not be installed in my system, instead of `extractall`? – Tahreem Iqbal Nov 10 '16 at 06:52
  • Yes, at least this used to be the case and I haven't heard that the compression method being added. Note that the zip archive format supports pluggable compression methods, and just because you have a library that supports the archive format doesn't mean it supports all algorithms. – Krumelur Nov 10 '16 at 06:54
  • but why does it work for small files and not for large? – Tahreem Iqbal Nov 10 '16 at 06:55
  • My guess: your archiving program changes method dynamically based on source input. Use `zipinfo -v zipfile.zip` to print information about each zip file to see what method it uses. – Krumelur Nov 10 '16 at 06:58
1

Recent versions of Microsoft Windows Explorer use Deflate64 compression when creating ZIP files larger than 2GB.(There are various methods for zipping, and it automatically switches the method based on file size).

This Deflate64 compression is not implemented in the zipfile module. You should use the zipfile-deflate64 module instead

Install using : pip install zipfile-deflate64

In your python file, import the module using import zipfile_deflate64 as zipfile

Now you can use it like the zipfile module:

with zipfile.ZipFile('NameofZipFile'+ '.zip', 'r') as zip_ref:
    zip_ref.extractall(dirname)

For more information you can read : https://pypi.org/project/zipfile-deflate64/