use BufWriter

This commit is contained in:
Dmitry Belyaev 2022-09-23 23:01:57 +03:00
parent 73f485eb59
commit aed59f4663
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -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<ConvertedFile>) {
/// write json data to zip files
async fn zip_writer(mut rx: UnboundedReceiver<ConvertedFile>) {
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<ConvertedFile>) {
.unwrap();
}
writer.close().await.unwrap();
buf.flush().await.unwrap();
println!("write done ✅");
}