Home > Software design >  Python creating binary zip file
Python creating binary zip file

Time:09-08

How do I create the binary contents of a zip file from .csv file binary contents? I don't want to actually write any files to memory. For instance, I have tried zipObj = ZipFile(outputZipFileName, 'w'), but that requires a file name, which means it is not just a file in binary format.

EDIT: I just found the answer at https://www.neilgrogan.com/py-bin-zip/

CodePudding user response:

The file in zipfile.ZipFile() can be an actual disk file or a file-like-object. Your solution probably lies in the io.BytesIO or io.StringIO classes. These let you create bytes or strings in memory and treat them like files in other functions and classes that take file-like-objects.

CodePudding user response:

Answer is at https://www.neilgrogan.com/py-bin-zip/. Turns out, using BytesIO alongside zipfile was the ticket!

  • Related