[ACCEPTED]-If I have the contents of a zipfile in a Python string, can I decompress it without writing it to a file?-python
Accepted answer
zipfile.ZipFile
accepts any file-like object, so you can 1 use StringIO
(2.x) or BytesIO
(3.x):
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.
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.