-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathmain.rs
More file actions
61 lines (50 loc) · 1.74 KB
/
main.rs
File metadata and controls
61 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#[cfg(feature = "parallel-chunking")]
use std::fs::File;
#[cfg(feature = "parallel-chunking")]
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use clap::Parser;
#[cfg(feature = "parallel-chunking")]
use deduplication::chunk_file_parallel;
#[derive(Debug, Parser)]
#[command(
version,
about,
long_about = "Parallel chunker with memory mapping and multi-threading. Requires --features parallel-chunking."
)]
struct ParallelChunkArgs {
/// Input file (required - stdin not supported in parallel mode)
#[arg(short, long)]
input: PathBuf,
/// Output file or uses stdout if not specified
#[arg(short, long)]
output: Option<PathBuf>,
/// Number of threads for parallel processing (0 = auto-detect)
#[arg(short, long, default_value = "0")]
threads: usize,
}
#[cfg(feature = "parallel-chunking")]
fn main() -> std::io::Result<()> {
let args = ParallelChunkArgs::parse();
// Process file with parallel implementation
let chunks = chunk_file_parallel(&args.input, Some(args.threads as u32))?;
// Setup output writer
let mut output: Box<dyn Write> = if let Some(save) = &args.output {
Box::new(BufWriter::new(File::create(save)?))
} else {
Box::new(std::io::stdout())
};
// Write results
for chunk in chunks {
output.write_all(format!("{} {}\n", chunk.hash, chunk.data.len()).as_bytes())?;
}
output.flush()?;
Ok(())
}
#[cfg(not(feature = "parallel-chunking"))]
fn main() -> std::io::Result<()> {
eprintln!("Error: parallel-chunk requires --features parallel-chunking");
eprintln!("Build with: cargo build --features parallel-chunking");
eprintln!("Or use the regular 'chunk' example for sequential processing.");
std::process::exit(1);
}