Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python using ZIP64 extensions when compressing large files

I have a script that compresses the output files. The problem is that one of the files is over 4Gigs. How would I convert my script to use ZIP64 extensions instead of the standard zip?

Here is how I am currently zipping:

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()

Thanks! Bill

like image 640
txwylde Avatar asked Apr 23 '15 17:04

txwylde


People also ask

How do I compress a ZIP file in Python?

To create your own compressed ZIP files, you must open the ZipFile object in write mode by passing 'w' as the second argument. When you pass a path to the write() method of a ZipFile object, Python will compress the file at that path and add it into the ZIP file.

How do I zip multiple files in Python?

Create a zip archive from multiple files in PythonCreate a ZipFile object by passing the new file name and mode as 'w' (write mode). It will create a new zip file and open it within ZipFile object. Call write() function on ZipFile object to add the files in it. call close() on ZipFile object to Close the zip file.

What does ZIP file ZIP file do?

Python's zipfile is a standard library module intended to manipulate ZIP files. This file format is a widely adopted industry standard when it comes to archiving and compressing digital data.


1 Answers

Check out zipfile-objects.

You can do this:

zf = zipfile.ZipFile('edw_files_' + datetime.strftime(date(), '%Y%m%d') + '.zip', mode='w', allowZip64 = True)
like image 160
Oladayo Oyelade Avatar answered Oct 26 '22 17:10

Oladayo Oyelade