Skip to content

Commit 1e1916e

Browse files
committed
improve downloading bar
1 parent f65db9d commit 1e1916e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

package.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,13 @@ def download(self, ver, path, url_from_srv):
197197
try:
198198
r = requests.get(url_from_srv, stream=True, headers=headers)
199199
total_size = int(r.headers.get('content-length', 0))
200-
flush_count = 0
201200

202-
with open(path, 'wb') as f:
203-
for chunk in tqdm(r.iter_content(chunk_size=1024), total=total_size//1024, unit='KB'):
201+
with open(path, 'wb') as f, tqdm(total=total_size, unit='B', unit_scale=True) as bar:
202+
# if the chunk_size is too large, the progress bar will not display
203+
for chunk in r.iter_content(chunk_size=1024):
204204
if chunk:
205205
f.write(chunk)
206-
f.flush()
207-
flush_count += 1
206+
bar.update(len(chunk))
208207

209208
retry_count = retry_count + 1
210209

0 commit comments

Comments
 (0)