use BufWriter

This commit is contained in:
Dmitry Belyaev 2022-09-23 21:30:23 +03:00
parent d48339b88b
commit 0ad014a544
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -10,7 +10,7 @@ use encoding::label::encoding_from_whatwg_label;
use encoding::EncodingRef; use encoding::EncodingRef;
use encoding::{DecoderTrap, EncoderTrap}; use encoding::{DecoderTrap, EncoderTrap};
use regex::Regex; use regex::Regex;
use tokio::io::AsyncReadExt; use tokio::io::{AsyncReadExt, BufWriter, AsyncWriteExt};
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::{fs, task}; use tokio::{fs, task};
@ -143,16 +143,18 @@ async fn writer_task(
output_filename: String, output_filename: String,
compression: Compression, compression: Compression,
) { ) {
let mut outfile = fs::File::create(output_filename) let outfile = fs::File::create(output_filename)
.await .await
.expect("output file"); .expect("output file");
let mut writer = ZipFileWriter::new(&mut outfile); let mut buf = BufWriter::with_capacity(100 * 1024 * 1024, outfile);
let mut writer = ZipFileWriter::new(&mut buf);
while let Some(FileData { name, data }) = rx.recv().await { while let Some(FileData { name, data }) = rx.recv().await {
let opts = EntryOptions::new(name, compression); let opts = EntryOptions::new(name, compression);
writer.write_entry_whole(opts, &data).await.unwrap(); writer.write_entry_whole(opts, &data).await.unwrap();
} }
writer.close().await.unwrap(); writer.close().await.unwrap();
buf.flush().await.unwrap();
println!("write done ✅"); println!("write done ✅");
} }