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 44b5d24
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions gdown/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,11 @@ def download(
f = output

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

if not quiet:
print(log_messages.get("start", "Downloading...\n"), file=sys.stderr, end="")
Expand All @@ -337,9 +340,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 44b5d24

Please sign in to comment.