From 67eadc7d6dce471e95417fac5db8179738ab7b26 Mon Sep 17 00:00:00 2001 From: TakWolf Date: Tue, 28 Jan 2025 03:21:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=B8=8B=E8=BD=BD=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB=EF=BC=8C=E6=B7=BB=E5=8A=A0=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/utils/download_util.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/utils/download_util.py b/tools/utils/download_util.py index e5ea3329..1b24432e 100644 --- a/tools/utils/download_util.py +++ b/tools/utils/download_util.py @@ -1,6 +1,7 @@ from pathlib import Path import httpx +from tqdm import tqdm def download_file(url: str, file_path: Path): @@ -8,6 +9,12 @@ def download_file(url: str, file_path: Path): assert response.is_success, url tmp_file_path = file_path.with_suffix(f'{file_path.suffix}.download') with tmp_file_path.open('wb') as file: - for chunk in response.iter_raw(1024): - file.write(chunk) + if 'Content-Length' in response.headers: + with tqdm(total=int(response.headers['Content-Length'])) as progress: + for chunk in response.iter_bytes(): + file.write(chunk) + progress.update(len(chunk)) + else: + for chunk in response.iter_bytes(): + file.write(chunk) tmp_file_path.rename(file_path)