Skip to content

Commit 3a8849c

Browse files
committed
feat: 增加文件下载缓冲机制
1 parent 9f8ce64 commit 3a8849c

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

source/application/download.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
class Download:
3131
SEMAPHORE = Semaphore(MAX_WORKERS)
32+
WRITE_BUFFER_SIZE = 1024 * 1024 * 100
3233
CONTENT_TYPE_MAP = {
3334
"image/png": "png",
3435
"image/jpeg": "jpeg",
@@ -248,11 +249,17 @@ def report(state: str, total: int | None = None) -> None:
248249
content_length = int(response.headers.get("content-length", 0) or 0)
249250
total = completed + content_length if content_length else None
250251
report("downloading", total)
252+
buffer = bytearray()
251253
async with open(temp, "ab") as f:
252254
async for chunk in response.aiter_content(self.chunk):
253-
await f.write(chunk)
255+
buffer.extend(chunk)
256+
if len(buffer) >= self.WRITE_BUFFER_SIZE:
257+
await f.write(bytes(buffer))
258+
buffer.clear()
254259
completed += len(chunk)
255260
report("downloading", total)
261+
if buffer:
262+
await f.write(bytes(buffer))
256263
real = await self.__suffix_with_file(
257264
temp,
258265
path,

static/Release_Notes.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
12. 优化视频下载链接提取逻辑
1515
13. 新增单独保存作品信息功能
1616
14. 重构项目内置请求延时机制
17-
15. 新增对 RedNote 的支持
18-
16. 支持图形用户交互界面
17+
15. 增加文件下载缓冲机制
18+
16. 新增对 RedNote 的支持
19+
17. 支持图形用户交互界面
1920

2021
⚠️ **升级提醒**:本次升级请将旧版本程序文件夹下的 _internal\Volume 文件夹,复制到新版本程序所在的文件夹内(与主程序在同一目录)
2122

0 commit comments

Comments
 (0)