Skip to content

Tag: python-zipfile

ZipFile does not store any text inside an archived file

The following code results in the file found in the zip being empty, instead of having some text in it: Answer Add flush to the file object: This problem also affects normal (non-temporary) files, so they’ll also need the flush treatment: Alternatively, de-denting the 2nd with block would avoid having t…

Python zipfile module doesn’t compress files

I have a problem with compression in Python. I know I should call the ZIP_DEFLATED method when writing to make the zip file compressed, but it does not work for me. I have 3 PDF documents in the C:zip directory. When I run the following code it works just fine: It makes the test.zip file without the compressi…

Faster alternative to Python’s zipfile module?

Is there a noticeably faster alternative to Python 2.7.4 zipfile module (with ZIP_DEFLATED) for zipping a large number of files into a single zip file? I had a look at czipfile https://pypi.python.org/pypi/czipfile/1.0.0, but that appears to be focused on faster decrypting (not compressing). I am routinely ha…

Is python zipfile thread-safe?

In a django project, I need to generate some pdf files for objects in db. Since each file takes a few seconds to generate, I use celery to run tasks asynchronously. Problem is, I need to add each file to a zip archive. I was planning to use the python zipfile module, but different tasks can be run in differen…