fmt
This commit is contained in:
parent
80382751df
commit
7d17e904fc
31
src/main.rs
31
src/main.rs
@ -244,22 +244,21 @@ impl<T> SplitTo<T> for Vec<T> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fn process_files(files: &&[PathBuf]) {
|
||||
if files.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let start_file = files[0].to_str().unwrap();
|
||||
println!("-> start from \"{}\" ({} files)", start_file, files.len());
|
||||
|
||||
|
||||
let zip_file = fs::File::open(BASE_FILENAME).unwrap();
|
||||
let zip_reader = io::BufReader::new(zip_file);
|
||||
let mut archive = zip::ZipArchive::new(zip_reader).unwrap();
|
||||
|
||||
files.iter().for_each(|name| {
|
||||
let name_str = name.to_str().unwrap();
|
||||
|
||||
|
||||
// parse txt file
|
||||
let file = archive.by_name(name_str).unwrap();
|
||||
let data = parse_file(file).unwrap();
|
||||
@ -273,7 +272,7 @@ fn process_files(files: &&[PathBuf]) {
|
||||
let mut outfile = fs::File::create(outfilename).unwrap();
|
||||
data.write_pretty(&mut outfile, 1).unwrap();
|
||||
});
|
||||
|
||||
|
||||
println!("<- done {} files (from \"{}\")", files.len(), start_file);
|
||||
}
|
||||
|
||||
@ -297,23 +296,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
})
|
||||
.collect();
|
||||
drop(archive);
|
||||
|
||||
|
||||
// check output directory
|
||||
let out_dir: PathBuf = OUTPUT_PATH.into();
|
||||
if out_dir.is_file() {
|
||||
return Err("output directory is file!".into());
|
||||
}
|
||||
else if !out_dir.exists() {
|
||||
return Err("output directory is file!".into());
|
||||
} else if !out_dir.exists() {
|
||||
fs::create_dir_all(out_dir)?;
|
||||
};
|
||||
|
||||
println!("processing {} files with {} threads...", source_files.len(), rayon::current_num_threads());
|
||||
|
||||
|
||||
println!(
|
||||
"processing {} files with {} threads...",
|
||||
source_files.len(),
|
||||
rayon::current_num_threads()
|
||||
);
|
||||
|
||||
// split vector and process its parts in parallel
|
||||
source_files.split_to(rayon::current_num_threads())
|
||||
source_files
|
||||
.split_to(rayon::current_num_threads())
|
||||
.par_iter()
|
||||
.for_each(process_files);
|
||||
|
||||
|
||||
println!("done");
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user