Skip to content

Commit 405441a

Browse files
committed
Show resume progress bar from the middle
1 parent 0354439 commit 405441a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

gdown/download.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ def download(
313313
tmp_file = None
314314
f = output
315315

316-
if tmp_file is not None and f.tell() != 0:
317-
headers = {"Range": "bytes={}-".format(f.tell())}
316+
start_size = f.tell()
317+
if tmp_file is not None and start_size:
318+
headers = {"Range": "bytes={}-".format(start_size)}
318319
res = sess.get(url, headers=headers, stream=True, verify=verify)
319320

320321
if not quiet:
@@ -337,9 +338,9 @@ def download(
337338
try:
338339
total = res.headers.get("Content-Length")
339340
if total is not None:
340-
total = int(total)
341+
total = int(total) + start_size
341342
if not quiet:
342-
pbar = tqdm.tqdm(total=total, unit="B", unit_scale=True)
343+
pbar = tqdm.tqdm(total=total, unit="B", initial=start_size, unit_scale=True)
343344
t_start = time.time()
344345
for chunk in res.iter_content(chunk_size=CHUNK_SIZE):
345346
f.write(chunk)

0 commit comments

Comments
 (0)