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
1 changed files with 5 additions and 3 deletions

View File

@ -10,7 +10,7 @@ use encoding::label::encoding_from_whatwg_label;
use encoding::EncodingRef;
use encoding::{DecoderTrap, EncoderTrap};
use regex::Regex;
use tokio::io::AsyncReadExt;
use tokio::io::{AsyncReadExt, BufWriter, AsyncWriteExt};
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::{fs, task};
@ -143,16 +143,18 @@ async fn writer_task(
output_filename: String,
compression: Compression,
) {
let mut outfile = fs::File::create(output_filename)
let outfile = fs::File::create(output_filename)
.await
.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 {
let opts = EntryOptions::new(name, compression);
writer.write_entry_whole(opts, &data).await.unwrap();
}
writer.close().await.unwrap();
buf.flush().await.unwrap();
println!("write done ✅");
}