Skip to content

Commit 6e00fbf

Browse files
committed
Show resume progress bar from the middle
1 parent 0354439 commit 6e00fbf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

gdown/download.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,11 @@ def download(
314314
f = output
315315

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

320323
if not quiet:
321324
print(log_messages.get("start", "Downloading...\n"), file=sys.stderr, end="")
@@ -337,9 +340,9 @@ def download(
337340
try:
338341
total = res.headers.get("Content-Length")
339342
if total is not None:
340-
total = int(total)
343+
total = int(total) + start_size
341344
if not quiet:
342-
pbar = tqdm.tqdm(total=total, unit="B", unit_scale=True)
345+
pbar = tqdm.tqdm(total=total, unit="B", initial=start_size, unit_scale=True)
343346
t_start = time.time()
344347
for chunk in res.iter_content(chunk_size=CHUNK_SIZE):
345348
f.write(chunk)

0 commit comments

Comments
 (0)