use BufWriter
This commit is contained in:
parent
73f485eb59
commit
aed59f4663
@ -8,7 +8,7 @@ use async_zip::Compression;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncReadExt, BufReader};
|
use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader, BufWriter};
|
||||||
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
|
||||||
|
|
||||||
const INPUT_FILENAME: &str = "baza_utf8.zip";
|
const INPUT_FILENAME: &str = "baza_utf8.zip";
|
||||||
@ -312,8 +312,9 @@ async fn reader_converter(tx: UnboundedSender<ConvertedFile>) {
|
|||||||
|
|
||||||
/// write json data to zip files
|
/// write json data to zip files
|
||||||
async fn zip_writer(mut rx: UnboundedReceiver<ConvertedFile>) {
|
async fn zip_writer(mut rx: UnboundedReceiver<ConvertedFile>) {
|
||||||
let mut file = fs::File::create(OUTPUT_FILENAME).await.unwrap();
|
let file = fs::File::create(OUTPUT_FILENAME).await.unwrap();
|
||||||
let mut writer = ZipFileWriter::new(&mut file);
|
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 {
|
while let Some(ConvertedFile { name, data }) = rx.recv().await {
|
||||||
// make output filename
|
// make output filename
|
||||||
@ -329,6 +330,7 @@ async fn zip_writer(mut rx: UnboundedReceiver<ConvertedFile>) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
writer.close().await.unwrap();
|
writer.close().await.unwrap();
|
||||||
|
buf.flush().await.unwrap();
|
||||||
|
|
||||||
println!("write done ✅");
|
println!("write done ✅");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user