3

I am using ZipFile in python to unzip a 6GB file. But it seems to be taking over 3hours to do so. I need to find a better alternative to fit within 20mins. Below is the code i have been working with which works perfectly fine but is very slow.

Python: 3.8.8

from zipfile import ZipFile
str_zipFile = 'C:\\Users\\Documents\\Test.zip'
str_pwd= '1234'

with ZipFile(str_zipFile) as zipObj:
    zipObj.extractall(pwd = bytes(str_pwd,'utf-8'))

Please suggest a faster method.

Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
KJoseph
  • 53
  • 5
  • You should try using python's `os` module to run the `zip` command in the system shell... Not sure whether that's not actually what ZipFile does, but if it doesn't it may be an alternative – Jake Nov 27 '21 at 17:01
  • Related to Jake's comment, you could try using 7zip with `os.system()` or `subprocess.call()`. My experience with 7zip awhile back was that it could be faster than the usual zip-file utilities. – mechanical_meat Nov 27 '21 at 17:03
  • 1
    Have you tested extraction with the typical tools? How long does that take? – James Z Nov 27 '21 at 19:24
  • Yes, I have tested it using a winzip or winrar it takes less than 5mins to unzip. – KJoseph Nov 28 '21 at 17:28
  • https://stackoverflow.com/questions/4997910/python-unzip-tremendously-slow, https://stackoverflow.com/questions/37141286/efficiently-read-one-file-from-a-zip-containing-a-lot-of-files-in-python – Albert Aug 24 '23 at 20:40

2 Answers2

0

Quote from Python zipfile module doc:

Decryption is extremely slow as it is implemented in native Python rather than C.

To get better performance, you can invoke an external program like unzip or 7z

oeter
  • 627
  • 2
  • 8
  • 23
-1

You could use subprocess.call(['unzip',filename,'-p',password]). This will call the unzip program that is used to expand zips. For more details: https://linux.die.net/man/1/unzip And don't forget to import the subprocess module!

Moldytzu
  • 76
  • 4