Skip to content

The only downloader you need. 下载器的集大成者。

perf(ftp_pack): 优化FTP数据传输性能

XiaoYouChRa7a9138c9cf7
diff --git a/features/ftp_pack/task.py b/features/ftp_pack/task.py
index c0dd4519..6bd01ed7 100644
--- a/features/ftp_pack/task.py
+++ b/features/ftp_pack/task.py
@@ -456,12 +456,13 @@ class FtpWorker(Worker):
chunk = await stream.read(min(FTP_CHUNK_SIZE, remaining))
if not chunk:
raise RuntimeError("FTP 数据流提前结束")
+ chunkSize = len(chunk)
await cfg.checkSpeedLimitation()
pwrite(self.fileHandle, chunk, subworker.progress)
- subworker.progress += len(chunk)
- remaining -= len(chunk)
- cfg.globalSpeed += len(chunk)
+ subworker.progress += chunkSize
+ remaining -= chunkSize
+ cfg.globalSpeed += chunkSize
finally:
self._closeTransfer(client, stream)
@@ -479,11 +480,12 @@ class FtpWorker(Worker):
chunk = await stream.read(FTP_CHUNK_SIZE)
if not chunk:
return
+ chunkSize = len(chunk)
await cfg.checkSpeedLimitation()
pwrite(self.fileHandle, chunk, subworker.progress)
- subworker.progress += len(chunk)
- cfg.globalSpeed += len(chunk)
+ subworker.progress += chunkSize
+ cfg.globalSpeed += chunkSize
finally:
self._closeTransfer(client, stream)
@@ -502,11 +504,12 @@ class FtpWorker(Worker):
if not chunk:
ftruncate(self.fileHandle, subworker.progress)
return
+ chunkSize = len(chunk)
await cfg.checkSpeedLimitation()
pwrite(self.fileHandle, chunk, subworker.progress)
- subworker.progress += len(chunk)
- cfg.globalSpeed += len(chunk)
+ subworker.progress += chunkSize
+ cfg.globalSpeed += chunkSize
finally:
self._closeTransfer(client, stream)