Python - Извлечение файлов из большого (6 ГБ +) почтового файла

у меня естьPython скрипт, где мне нужно извлечь содержимое файла ZIP. Тем не менее, размер почтового файла составляет более 6 ГБ.

Существует много информации оzlib а такжеzipfile модули, однако, я не могу найти единый подход, который работает в моем случае. У меня есть код:

with zipfile.ZipFile(fname, "r") as z:
        try:
            log.info("Extracting %s " %fname)
            head, tail = os.path.split(fname)
            z.extractall(folder + "/" + tail)
        except zipfile.BadZipfile:
            log.error("Bad Zip file")
        except zipfile.LargeZipFile:
            log.error("Zip file requires ZIP64 functionality but that has not been enabled (i.e., too large)")
        except zipfile.error:
            log.error("Error decompressing ZIP file")

Я знаю, что мне нужно установитьallowZip64 вtrue но я не уверен, как это сделать. Тем не менее, даже как есть,LargeZipFile исключение не выбрасывается, а вместоBadZipFile исключение Понятия не имею почему.

Кроме того, это лучший способ справиться с извлечением архива ZIP 6GB ???

Обновление: изменениеBadZipfile Исключение из этого:

except zipfile.BadZipfile as inst:
        log.error("Bad Zip file")
        print type(inst)     # the exception instance
        print inst.args      # arguments stored in .args
        print inst

показывает:

<class 'zipfile.BadZipfile'>
('Bad magic number for file header',)

Обновление № 2:

Полный трекбек показывает

BadZipfile                                Traceback (most recent call last)
<ipython-input-1-8d34a9f58f6a> in <module>()
      6     for member in z.infolist():
      7         print member.filename[-70:],
----> 8         f = z.open(member, 'r')
      9         size = 0
     10         while True:

/Users/brspurri/anaconda/python.app/Contents/lib/python2.7/zipfile.pyc in open(self, name, mode, pwd)
    965             fheader = struct.unpack(structFileHeader, fheader)
    966             if fheader[_FH_SIGNATURE] != stringFileHeader:
--> 967                 raise BadZipfile("Bad magic number for file header")
    968 
    969             fname = zef_file.read(fheader[_FH_FILENAME_LENGTH])

BadZipfile: Bad magic number for file header

Выполнение кода:

import sys
import zipfile

with open(zip_filename, 'rb') as zf:
    z = zipfile.ZipFile(zf, allowZip64=True)
    z.testzip()

doesn't output anything.

Ответы на вопрос(1)

Ваш ответ на вопрос