Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split PDFRip into multiple crates #26

Merged
merged 14 commits into from
Feb 15, 2024
Merged

Conversation

Pommaq
Copy link

@Pommaq Pommaq commented Feb 10, 2024

This is a suggestion for how #23 can be performed, additionally I added a few tests and some code cleanup.
It also partially splits all CLI interaction away from main.rs and into a separate crate as suggested by me in #18, the only part left would be to move the ProgressBar away from engine.rs and into cli-interaction as well somehow.

One way would be to allow engine.rs to take a callback which in the case of ProgressBar would simply increment the bar,
then wrap engine::crack_file with something like

fn wrapper(
    no_workers: usize,
    cracker: PDFCracker,
    mut producer: Box<dyn Producer>,
) -> anyhow::Result<Option<Vec<u8>>> {
    let progress_bar = ProgressBar::new(producer.size() as u64);
    progress_bar.set_draw_delta(1000);
    progress_bar.set_style(ProgressStyle::default_bar()
            .template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos:>7}/{len:7} {percent}% {per_sec} ETA: {eta}"));

    let callback = || {
        progress_bar.inc(1);
    };

    let res = crack_file(no_workers, cracker, producer, callback);
    progress_bar.finish();

    return res;
}

@Pommaq
Copy link
Author

Pommaq commented Feb 10, 2024

Eh whatever, I had a bit of extra time.
Now the CLI interface (all our non-log prints and parameter parsing) is compartmentalized into the cli-interface crate. This should ease future changes where stdout might not be available.

@Pommaq
Copy link
Author

Pommaq commented Feb 12, 2024

I am removing the workflow from this PR since I add one in #27 anyways

@mufeedvh
Copy link
Owner

This looks well organized now, nice! Thank you so much for the effort you're putting into this project @Pommaq, I really appreciate it! 🙌

@mufeedvh mufeedvh merged commit 7089c89 into mufeedvh:main Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants