Skip to content

Commit

Permalink
Merge 21f217e into e3a3655
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgill86 committed Jun 28, 2019
2 parents e3a3655 + 21f217e commit f3fb562
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions neurotic/datasets/download.py
Expand Up @@ -170,9 +170,14 @@ def _download(url, local_file, bytes_per_chunk=1024*8, show_progress=True):

with urllib.request.urlopen(urllib.parse.quote(url, safe='/:')) as dist:
with open(local_file, 'wb') as f:
file_size_in_bytes = int(dist.headers['Content-Length'])
num_chunks = int(np.ceil(file_size_in_bytes/bytes_per_chunk))
if show_progress:
if 'Content-Length' in dist.headers:
# knowing the file size allows progress to be displayed
file_size_in_bytes = int(dist.headers['Content-Length'])
num_chunks = int(np.ceil(file_size_in_bytes/bytes_per_chunk))
else:
# progress can't be displayed, but other stats can be
num_chunks = np.inf
pbar = tqdm(total=num_chunks*bytes_per_chunk, unit='B', unit_scale=True)
while True:
chunk = dist.read(bytes_per_chunk)
Expand Down

0 comments on commit f3fb562

Please sign in to comment.