t.total = tsize
t.update(b * bsize - t.n)
headers = resp.info()
// This capitalization was copied from the stdlib too
if "content-length" in headers:
size = int(headers["Content-Length"])
update_to(blocknum, bs, size)
while True:
block = resp.read(bs)
if not block:
break
read += len(block)
f.write(block)
blocknum += 1
update_to(blocknum, bs, size)
// fmt: on
After Change
path.open("wb") as f, \
urlopen(Request(url, headers={"User-agent": "scanpy-user"})) as resp:
t.total = int(resp.info().get("content-length", 0))
block = resp.read(blocksize)
while block:
f.write(block)
blocknum += 1
t.update(blocknum * blocksize - t.n)
block = resp.read(blocksize)
// fmt: on
except Exception:
// Make sure file doesn’t exist half-downloaded
if path.is_file():