简体   繁体   中英

Python creating binary zip file

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/

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM