In my app engine script (using the Python API), I'm using this code to dynamically generate zip files and serve them back to the user. When I download and extract the generated zip file and I'm running OS X, the permissions of each file extracted from the archive is 0, forcing me to chmod them. I'd rather not have my users have to do the same. Is there a way to fix this?
Asked
Active
Viewed 163 times
1
-
1http://stackoverflow.com/questions/279945/set-permissions-on-a-compressed-file-in-python may be helpful, although the solution may need to be adapted a bit to work within a StringIO. – Wooble Dec 15 '10 at 17:22
1 Answers
1
Yup, see the docs for the Python zipfile module. Specifically, the signature of the writestr
method, which is:
ZipFile.writestr(zinfo_or_arcname, bytes[, compress_type])
The first argument can be the filename, or a ZipInfo object, which allows you to specify information about the file to be stored. I believe the relevant field to set to change the permissions of the file is the external_attr, but some experimentation reading existing zip files may be required to determine this.

Nick Johnson
- 100,655
- 16
- 128
- 198