下载/主界面优化
This commit is contained in:
@@ -318,13 +318,14 @@ async fn download_segment_with_client(
|
||||
match stream.next().await {
|
||||
Some(Ok(chunk)) => {
|
||||
buf.extend_from_slice(&chunk);
|
||||
// 接收到数据立即更新进度(避免监控周期内进度无变化导致速度显示为 0)
|
||||
local_completed += chunk.len() as u64;
|
||||
progress.store(local_completed, Ordering::Relaxed);
|
||||
// 积累到 64KB 再写入(减少 I/O 次数)
|
||||
if buf.len() >= 64 * 1024 {
|
||||
file.write_all(&buf)
|
||||
.await
|
||||
.map_err(|e| format!("写入文件失败: {}", e))?;
|
||||
local_completed += buf.len() as u64;
|
||||
progress.store(local_completed, Ordering::Relaxed);
|
||||
// 限速
|
||||
limiter.consume(buf.len() as u64).await;
|
||||
buf.clear();
|
||||
@@ -339,8 +340,7 @@ async fn download_segment_with_client(
|
||||
file.write_all(&buf)
|
||||
.await
|
||||
.map_err(|e| format!("写入文件失败: {}", e))?;
|
||||
local_completed += buf.len() as u64;
|
||||
progress.store(local_completed, Ordering::Relaxed);
|
||||
// local_completed 和 progress 已在接收 chunk 时更新
|
||||
limiter.consume(buf.len() as u64).await;
|
||||
buf.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user