From 97156aa1abaaaa75b3b164bc8da898a030176335 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 18 Jun 2023 02:00:55 +0200 Subject: [PATCH] use copy instead of reading the whole file into memory and then writing all this should call read & write repeatedly until the whole file is copied into the target file (at the current position) --- src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 51a53b5..98ea03c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -712,12 +712,11 @@ pub async fn convert_ts_to_mp4(video_mp4: &PathBuf, video_ts: &PathBuf) -> Resul pub async fn combine_parts_into_single_ts(files: Vec, video_ts: &PathBuf) -> Result<()> { debug!("combining all parts of video"); debug!("part amount: {}", files.len()); - let mut video_ts_file = tokio::fs::File::create(&video_ts).await?; + let mut video_ts_file = File::create(&video_ts).await?; for file_path in &files { debug!("{:?}", file_path.file_name()); - let file = tokio::fs::read(&file_path).await?; - trace!("size of file: {}", file.len()); - video_ts_file.write_all(&file).await?; + let mut file = File::open(&file_path).await?; + tokio::io::copy(&mut file, &mut video_ts_file).await?; tokio::fs::remove_file(&file_path).await?; } Ok(())