Created
September 4, 2014 16:26
-
-
Save denysbutenko/cb69d89fd5682865093e 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 os | |
from zipfile import ZipFile | |
from StringIO import StringIO | |
from urllib import urlopen | |
from sys import platform as _platform | |
def unzip_from_stream(url, dest_dir): | |
original_zip = ZipFile(StringIO(urlopen(url).read())) | |
if _platform == "win32": | |
original_zip.extractall(dest_dir) | |
elif _platform in ["linux", "linux2", "darwin"]: | |
new_zip = ZipFile(StringIO(), 'w') | |
with original_zip as f: | |
for item in f.infolist(): | |
new_filename = item.filename.replace('\\', '/') | |
new_zip.writestr(new_filename, f.read(item)) | |
new_zip.extractall(dest_dir) | |
new_zip.close() | |
original_zip.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment