The Python ZipFile API seems to allow the passing of a file path to ZipFile.write or a byte string to ZipFile.writestr but nothing in between. I would like to be able to pass a file like object, in this case a django.core.files.storage.DefaultStorage but any file-like object in principle. At the moment I think I’m going to have to either save the file to disk, or read it into memory. Neither of these is perfect.
The Python ZipFile API seems to allow the passing of a file path to
Share
You are correct, those are the only two choices. If your
DefaultStorageobject is large, you may want to go with saving it to disk first; otherwise, I would use:If
default_storage_objectis aStringIOobject, it can usedefault_storage_object.getvalue().