feat(upload): Use BufWriter for file downloads. (#684)

This commit is contained in:
Fabian-Lars
2023-10-25 12:25:33 +02:00
committed by GitHub
parent 8dd371814a
commit 1712f27b77
+6 -2
View File
@@ -9,7 +9,10 @@ use tauri::{
plugin::{Builder as PluginBuilder, TauriPlugin},
Runtime, Window,
};
use tokio::{fs::File, io::AsyncWriteExt};
use tokio::{
fs::File,
io::{AsyncWriteExt, BufWriter},
};
use tokio_util::codec::{BytesCodec, FramedRead};
use read_progress_stream::ReadProgressStream;
@@ -64,7 +67,7 @@ async fn download<R: Runtime>(
let response = request.send().await?;
let total = response.content_length().unwrap_or(0);
let mut file = File::create(file_path).await?;
let mut file = BufWriter::new(File::create(file_path).await?);
let mut stream = response.bytes_stream();
while let Some(chunk) = stream.try_next().await? {
@@ -78,6 +81,7 @@ async fn download<R: Runtime>(
},
);
}
file.flush().await?;
Ok(id)
}