Skip to content

Commit bb05c59

Browse files
authored
Merge pull request #2091 from bsipocz/progressbar_fix_downloaded_amount
Fix downloaded amount for progressbar
2 parents 1a859e5 + 97b1a1c commit bb05c59

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

CHANGES.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ esa.xmm_newton
1616
- Adding the extraction epic light curves. [#2017]
1717
- Adding the extraction of epic spectra. [#2017]
1818

19+
1920
Service fixes and enhancements
2021
------------------------------
2122

@@ -51,6 +52,13 @@ atomic
5152
- Change URL to https [#2088]
5253

5354

55+
Infrastructure, Utility and Other Changes and Additions
56+
-------------------------------------------------------
57+
58+
- Fixed progressbar download to report the correct downloaded amount. [#2091]
59+
60+
61+
5462
0.4.2 (2021-05-14)
5563
==================
5664

astroquery/query.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,8 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
385385
if length is not None:
386386
statinfo = os.stat(local_filepath)
387387
if statinfo.st_size != length:
388-
log.warning("Found cached file {0} with size {1} that is "
389-
"different from expected size {2}"
390-
.format(local_filepath,
391-
statinfo.st_size,
392-
length))
388+
log.warning(f"Found cached file {local_filepath} with size {statinfo.st_size} "
389+
f"that is different from expected size {length}")
393390
open_mode = 'wb'
394391
else:
395392
log.info("Found cached file {0} with expected size {1}."
@@ -421,20 +418,16 @@ def _download_file(self, url, local_filepath, timeout=None, auth=None,
421418
else:
422419
progress_stream = io.StringIO()
423420

424-
with ProgressBarOrSpinner(
425-
length, ('Downloading URL {0} to {1} ...'
426-
.format(url, local_filepath)),
427-
file=progress_stream) as pb:
421+
with ProgressBarOrSpinner(length, f'Downloading URL {url} to {local_filepath} ...',
422+
file=progress_stream) as pb:
428423
with open(local_filepath, open_mode) as f:
429424
for block in response.iter_content(blocksize):
430425
f.write(block)
431-
bytes_read += blocksize
426+
bytes_read += len(block)
432427
if length is not None:
433-
pb.update(bytes_read if bytes_read <= length else
434-
length)
428+
pb.update(bytes_read if bytes_read <= length else length)
435429
else:
436430
pb.update(bytes_read)
437-
438431
response.close()
439432
return response
440433

0 commit comments

Comments
 (0)