-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
28 lines (23 loc) · 902 Bytes
/
utils.py
File metadata and controls
28 lines (23 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import zipfile
import zlib
from urllib.request import urlretrieve, urlopen
def download_unzip(url: str, file_path: str):
print(f'Downloading from {url}...')
zip_file_path = os.path.join(os.path.dirname(file_path), os.path.basename(url))
urlretrieve(url, zip_file_path)
with zipfile.ZipFile(zip_file_path) as f:
f.extractall(out_file_path)
os.remove(zip_file_path)
def download_unzip_streaming(url: str, file_path: str):
'''Broken: dec.decompress() throws error regardless of wbits param'''
print(f'Downloading from {url}...')
dec = zlib.decompressobj(zlib.MAX_WBITS + 32)
with urlopen(url) as stream:
with open(file_path, 'wt') as f:
for chunk in stream:
rv = dec.decompress(chunk)
if rv:
f.write(rv)
if dec.unused_data:
f.write(dec.flush())