Process files in parallel
This commit is contained in:
parent
04f03b4efc
commit
20e10eecb4
1 changed files with 8 additions and 3 deletions
11
src/main.rs
11
src/main.rs
|
|
@ -1,6 +1,6 @@
|
||||||
use clap::{Parser, ValueHint};
|
use clap::{Parser, ValueHint};
|
||||||
use image::DynamicImage;
|
use image::DynamicImage;
|
||||||
use log::info;
|
use log::*;
|
||||||
use pdf_writer::{Content, Filter, Finish, Name, Pdf, Rect, Ref};
|
use pdf_writer::{Content, Filter, Finish, Name, Pdf, Rect, Ref};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
|
@ -166,14 +166,19 @@ fn convert_directory(
|
||||||
directory: &Path,
|
directory: &Path,
|
||||||
output_dir: &Path,
|
output_dir: &Path,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
info!("Walking {:?}", directory);
|
debug!("Walking {:?}", directory);
|
||||||
|
let mut entries = Vec::new();
|
||||||
for entry in WalkDir::new(directory) {
|
for entry in WalkDir::new(directory) {
|
||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
if path.is_file() && path.extension() == Some(OsStr::new("cbz")) {
|
if path.is_file() && path.extension() == Some(OsStr::new("cbz")) {
|
||||||
convert_cbz(path, output_dir)?;
|
entries.push(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entries
|
||||||
|
.par_iter()
|
||||||
|
.for_each(|entry| convert_cbz(entry.path(), output_dir).unwrap());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue