mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 06:12:53 +08:00
🐛 fix(http_utils): 流式下载Content-Length错误 (#1647)
This commit is contained in:
parent
32c11b9919
commit
207f947a1c
@ -1 +1 @@
|
|||||||
__version__: v0.2.2-f9c7360
|
__version__: v0.2.2-d539b1f
|
||||||
|
|||||||
@ -286,7 +286,9 @@ class AsyncHttpx:
|
|||||||
f"Path: {path.absolute()}"
|
f"Path: {path.absolute()}"
|
||||||
)
|
)
|
||||||
async with aiofiles.open(path, "wb") as wf:
|
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
|
with rich.progress.Progress( # type: ignore
|
||||||
rich.progress.TextColumn(path.name), # type: ignore
|
rich.progress.TextColumn(path.name), # type: ignore
|
||||||
"[progress.percentage]{task.percentage:>3.0f}%", # type: ignore
|
"[progress.percentage]{task.percentage:>3.0f}%", # type: ignore
|
||||||
@ -295,7 +297,8 @@ class AsyncHttpx:
|
|||||||
rich.progress.TransferSpeedColumn(), # type: ignore
|
rich.progress.TransferSpeedColumn(), # type: ignore
|
||||||
) as progress:
|
) as progress:
|
||||||
download_task = progress.add_task(
|
download_task = progress.add_task(
|
||||||
"Download", total=total
|
"Download",
|
||||||
|
total=total if total else None,
|
||||||
)
|
)
|
||||||
async for chunk in response.aiter_bytes():
|
async for chunk in response.aiter_bytes():
|
||||||
await wf.write(chunk)
|
await wf.write(chunk)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user