Skip to content

Commit

Permalink
Show resume progress bar from the middle
Browse files Browse the repository at this point in the history
  • Loading branch information
wkentaro committed May 12, 2024
1 parent 0354439 commit 405441a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ def download(
tmp_file = None
f = output

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

if not quiet:
Expand All @@ -337,9 +338,9 @@ def download(
try:
total = res.headers.get("Content-Length")
if total is not None:
total = int(total)
total = int(total) + start_size
if not quiet:
pbar = tqdm.tqdm(total=total, unit="B", unit_scale=True)
pbar = tqdm.tqdm(total=total, unit="B", initial=start_size, unit_scale=True)
t_start = time.time()
for chunk in res.iter_content(chunk_size=CHUNK_SIZE):
f.write(chunk)
Expand Down

0 comments on commit 405441a

Please sign in to comment.