This commit is contained in:
Dmitry Belyaev 2022-09-12 16:30:13 +03:00
parent 9cb95c435a
commit ed87fd17ea
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3

View File

@ -4,7 +4,6 @@ extern crate json;
extern crate tokio;
use async_zip::read::fs::ZipFileReader;
use futures::future;
use std::path::PathBuf;
use std::str::FromStr;
use tokio::fs;
@ -221,8 +220,11 @@ async fn parse_file(
Ok(ctx.data.clone())
}
async fn process_file(index: usize, name: String) -> Result<(), Box<dyn std::error::Error>> {
let archive = ZipFileReader::new(String::from(BASE_FILENAME)).await?;
async fn process_file(
archive: &ZipFileReader,
index: usize,
name: String,
) -> Result<(), Box<dyn std::error::Error>> {
let entry_reader = archive.entry_reader(index).await?;
// make output filename
@ -255,7 +257,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
})
.map(|item| (item.0, item.1.name().to_string()))
.collect();
drop(archive);
// check output directory
match fs::metadata(OUTPUT_PATH).await {
@ -266,17 +267,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("processing {} files ...", source_files.len());
let mut handles = vec![];
for index in source_files {
let i = index.clone();
let handle = tokio::spawn(async move {
process_file(i.0, i.1).await.unwrap();
});
handles.push(handle);
for i in source_files {
process_file(&archive, i.0, i.1).await?;
}
future::join_all(handles).await;
println!("done");
Ok(())
}