Skip to content

Instantly share code, notes, and snippets.

@syntaxsugar
Created May 27, 2014 07:22
Show Gist options
  • Select an option

  • Save syntaxsugar/9c5cb086965e69fd1444 to your computer and use it in GitHub Desktop.

Select an option

Save syntaxsugar/9c5cb086965e69fd1444 to your computer and use it in GitHub Desktop.
import StringIO
import zipfile
def foobar():
in_memory = StringIO.StringIO()
z = zipfile.ZipFile(in_memory, 'a')
z.writestr("file.txt", 'some data')
z.writestr("file2.txt", 'some data2')
z.close()
in_memory.seek(0)
return in_memory.read()
def main():
data = foobar()
print type(data)
print len(data)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment