Skip to content

Commit

Permalink
bump version, fix get_file content-length
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Oct 10, 2020
1 parent 194e7cb commit bac7b4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion brainweb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .utils import __all__ # NOQA
__author__ = "Casper O. da Costa-Luis <casper.dcl@physics.org>"
__licence__ = __license__ = "[MPLv2.0](https://www.mozilla.org/MPL/2.0)"
__version__ = "1.6.1"
__version__ = "1.6.2"
7 changes: 4 additions & 3 deletions brainweb/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Shape(object):
brainweb = mMR * Res.mMR / Res.brainweb


def get_file(fname, origin, cache_dir=None):
def get_file(fname, origin, cache_dir=None, chunk_size=None):
"""
Downloads a file from a URL if it not already in the cache.
By default the file at the url `origin` is downloaded to the
Expand Down Expand Up @@ -177,11 +177,12 @@ def get_file(fname, origin, cache_dir=None):
log.debug("Downloading %s from %s" % (fpath, origin))
try:
d = requests.get(origin, stream=True)
with tqdm(total=d.headers.get('Content-length', None), desc=fname,
with tqdm(total=float(d.headers.get('Content-length') or 0),
desc=fname,
unit="B", unit_scale=True, unit_divisor=1024,
leave=False) as fprog:
with open(fpath, 'wb') as fo:
for chunk in d.iter_content(chunk_size=None):
for chunk in d.iter_content(chunk_size=chunk_size):
fo.write(chunk)
fprog.update(len(chunk))
fprog.total = fprog.n
Expand Down

0 comments on commit bac7b4c

Please sign in to comment.