Created
June 11, 2014 19:53
-
-
Save rectalogic/b93722796efc9983f7d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zipfile | |
import sys | |
class StreamFile(object): | |
def __init__(self, fileobj): | |
self.fileobj = fileobj | |
self.pos = 0 | |
def write(self, str): | |
self.fileobj.write(str) | |
self.pos += len(str) | |
def tell(self): | |
return self.pos | |
def flush(self): | |
self.fileobj.flush() | |
# Wrap a stream so ZipFile can use it | |
out = StreamFile(sys.stdout) | |
z = zipfile.ZipFile(out, 'w', zipfile.ZIP_STORED) | |
z.writestr("hello1.txt", "this is hello1 contents\n") | |
z.writestr("hello2.txt", "this is hello2 contents\n") | |
z.writestr("hello3.txt", "this is hello3 contents\n") | |
z.writestr("hello4.txt", "this is hello4 contents\n") | |
z.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment