Skip to content

Instantly share code, notes, and snippets.

@monokrome
Created May 14, 2011 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokrome/972749 to your computer and use it in GitHub Desktop.
Save monokrome/972749 to your computer and use it in GitHub Desktop.
A zip file which happens to let content overlay it's files. Use with a dash of StringIO for grand results.
import zipfile
class OverlayZipFile(zipfile.ZipFile):
""" Adds a method for overlaying a zip file with a given directory, or another
zip file. """
def overlay(self, content):
""" Overlays content over the zip file represented by 'self'.
Receives a zip file, and write's it's entire content over the zip file which
is represented by 'self' - overwriting any files in the current zip with the
any files of the same name which are within the provided content zip file.
"""
for filename in content.namelist():
self.writestr(filename, content.read(filename))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment