From aed59f466349dd0eaad6f3b5eb144e01faa7ea2c Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 23 Sep 2022 23:01:57 +0300 Subject: [PATCH] use BufWriter --- src/main.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5c7551e..a5e2ea2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use async_zip::Compression; use std::path::PathBuf; use std::str::FromStr; use tokio::fs; -use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader}; +use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; const INPUT_FILENAME: &str = "baza_utf8.zip"; @@ -312,8 +312,9 @@ async fn reader_converter(tx: UnboundedSender) { /// write json data to zip files async fn zip_writer(mut rx: UnboundedReceiver) { - let mut file = fs::File::create(OUTPUT_FILENAME).await.unwrap(); - let mut writer = ZipFileWriter::new(&mut file); + let file = fs::File::create(OUTPUT_FILENAME).await.unwrap(); + let mut buf = BufWriter::with_capacity(100 * 1024 * 1024, file); + let mut writer = ZipFileWriter::new(&mut buf); while let Some(ConvertedFile { name, data }) = rx.recv().await { // make output filename @@ -329,6 +330,7 @@ async fn zip_writer(mut rx: UnboundedReceiver) { .unwrap(); } writer.close().await.unwrap(); + buf.flush().await.unwrap(); println!("write done ✅"); }