Skip to content

Instantly share code, notes, and snippets.

@mdornseif
Created May 1, 2011 20:44
Show Gist options
  • Save mdornseif/950860 to your computer and use it in GitHub Desktop.
Save mdornseif/950860 to your computer and use it in GitHub Desktop.
This is shows how to generate ZIP files in the blobstore.
def store_pdfs_in_zip():
docs = Dokument.all().order('updated_at')
file_name = files.blobstore.create(mime_type='application/zip',
_blobinfo_uploaded_filename='test.zip')
with files.open(file_name, 'w') as f:
z = blobstoreZipFile(f)
for doc in docs.fetch(75):
pdf = doc.data
fname = "%s-%s.pdf" % (doc.designator, doc.updated_at)
fname = fname.encode('ascii', 'replace')
z.writestr(fname, pdf, date_time=doc.updated_at.timetuple()[:6])
# Finalize ZIP file and write directory
z.flush()
# Finalize the file in the blobstore
files.finalize(file_name)
# Get the file's blob key
blob_key = files.blobstore.get_blob_key(file_name)
@mdornseif
Copy link
Author

@carlopires I tested it and then moved to tar.bz2. Did you check the actual contents of the file?

hexdump -C /tmp/pages.zip | head -n 20

@carlopires
Copy link

Do you mean the file generated is bzip2 compressed?

@mdornseif
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment