From d247a02cd9656b7ca15128e517c8e995af66903a Mon Sep 17 00:00:00 2001 From: HsiangNianian Date: Tue, 13 Jan 2026 15:56:32 +0800 Subject: feat: refactor download logic to use chunking for response handling --- src-tauri/src/core/downloader.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src-tauri') diff --git a/src-tauri/src/core/downloader.rs b/src-tauri/src/core/downloader.rs index 0ba9aec..33404e9 100644 --- a/src-tauri/src/core/downloader.rs +++ b/src-tauri/src/core/downloader.rs @@ -72,21 +72,14 @@ pub async fn download_files(window: Window, tasks: Vec) -> Result< } match client.get(&task.url).send().await { - Ok(resp) => { + Ok(mut resp) => { let total_size = resp.content_length().unwrap_or(0); let mut file = match tokio::fs::File::create(&task.path).await { Ok(f) => f, Err(e) => return Err(format!("Create file error: {}", e)), }; - // reqwest::Response::bytes_stream() is only available if the 'stream' feature is enabled - // But we used 'blocking' and 'json'. We should add 'stream' feature to Cargo.toml? - // Or just use chunk(). - // Actually, let's just create a loop if stream feature is missing or use chunk() manually if blocking is used? - // Wait, we are in async context. 'reqwest' dependency in Cargo.toml has 'json', 'blocking' - // We need 'stream' feature for .bytes_stream() - - // Let's use loop with chunk() + let mut downloaded: u64 = 0; loop { match resp.chunk().await { Ok(Some(chunk)) => { -- cgit v1.2.3-70-g09d2