🐛 fix(http_utils): 流式下载Content-Length错误 (#1647)

This commit is contained in:
AkashiCoin
2024-09-22 17:12:21 +08:00
committed by GitHub
parent 32c11b9919
commit 207f947a1c
2 changed files with 6 additions and 3 deletions
+5 -2
View File
@@ -286,7 +286,9 @@ class AsyncHttpx:
f"Path: {path.absolute()}"
)
async with aiofiles.open(path, "wb") as wf:
total = int(response.headers["Content-Length"])
total = int(
response.headers.get("Content-Length", 0)
)
with rich.progress.Progress( # type: ignore
rich.progress.TextColumn(path.name), # type: ignore
"[progress.percentage]{task.percentage:>3.0f}%", # type: ignore
@@ -295,7 +297,8 @@ class AsyncHttpx:
rich.progress.TransferSpeedColumn(), # type: ignore
) as progress:
download_task = progress.add_task(
"Download", total=total
"Download",
total=total if total else None,
)
async for chunk in response.aiter_bytes():
await wf.write(chunk)