[ACCEPTED]-If I have the contents of a zipfile in a Python string, can I decompress it without writing it to a file?-python
zipfile.ZipFile accepts any file-like object, so you can 1 use
StringIO (2.x) or
try: from cStringIO import StringIO except: from StringIO import StringIO import zipfile fp = StringIO('PK\x03\x04\x14') zfp = zipfile.ZipFile(fp, "r")
Wrap your string in a cStringIO object. It looks, acts, and 2 quacks like a file object, but resides in 1 memory.
More Related questions