Python in-memory zip library

后端 未结 4 1063
逝去的感伤
逝去的感伤 2020-11-29 19:14

Is there a Python library that allows manipulation of zip archives in memory, without having to use actual disk files?

The ZipFile library does not allow you to upd

4条回答
  •  旧时难觅i
    2020-11-29 19:40

    According to the Python docs:

    class zipfile.ZipFile(file[, mode[, compression[, allowZip64]]])
    
      Open a ZIP file, where file can be either a path to a file (a string) or a file-like object. 
    

    So, to open the file in memory, just create a file-like object (perhaps using BytesIO).

    file_like_object = io.BytesIO(my_zip_data)
    zipfile_ob = zipfile.ZipFile(file_like_object)
    

提交回复
热议问题