2026-08-05 18:05:04 -04:00
|
|
|
//! Print what the legacy-Office extractor gets out of a real file.
|
|
|
|
|
//!
|
2026-09-25 14:58:51 -04:00
|
|
|
//! The unit tests prove the parsers agree with the format specs as read, on
|
|
|
|
|
//! fixtures they build; this runs them against files a real producer wrote.
|
2026-08-05 18:05:04 -04:00
|
|
|
//!
|
|
|
|
|
//! cargo run --example oleprobe -- some.doc some.xls some.ppt
|
|
|
|
|
|
2026-10-11 20:32:00 -04:00
|
|
|
use std::io::Read;
|
2026-08-05 18:05:04 -04:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
2026-08-25 01:04:36 -04:00
|
|
|
use quicksearch_core::config::Config;
|
2026-10-11 20:32:00 -04:00
|
|
|
use quicksearch_core::extract::{Registry, Scratch};
|
|
|
|
|
use quicksearch_core::mime::guess_mime_from_head;
|
2026-08-05 18:05:04 -04:00
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let mut failures = 0;
|
2026-08-25 01:04:36 -04:00
|
|
|
let config = Config::default();
|
2026-10-11 20:32:00 -04:00
|
|
|
let registry = Registry::default_set();
|
2026-08-25 01:04:36 -04:00
|
|
|
let mut scratch = Scratch::new(&config);
|
2026-08-05 18:05:04 -04:00
|
|
|
for arg in std::env::args().skip(1) {
|
|
|
|
|
let path = Path::new(&arg);
|
|
|
|
|
println!("=== {} ===", path.display());
|
2026-10-11 20:32:00 -04:00
|
|
|
// The dispatch a real index takes: the MIME sniffed from the name and
|
|
|
|
|
// the head the walk reads.
|
|
|
|
|
let mut head = Vec::new();
|
|
|
|
|
let opened = std::fs::File::open(path).and_then(|f| {
|
|
|
|
|
f.take(config.processing.hash_length as u64)
|
|
|
|
|
.read_to_end(&mut head)
|
|
|
|
|
});
|
|
|
|
|
if let Err(e) = opened {
|
|
|
|
|
failures += 1;
|
|
|
|
|
println!("FAILED: {}", e);
|
|
|
|
|
println!();
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let mime = guess_mime_from_head(path, &head).unwrap_or_default();
|
|
|
|
|
println!("(mime {})", mime);
|
2026-08-25 01:04:36 -04:00
|
|
|
let mut text = String::new();
|
2026-10-11 20:32:00 -04:00
|
|
|
match registry.extract(path, mime, &mut text, &mut scratch) {
|
|
|
|
|
Ok(true) => {
|
2026-08-05 18:05:04 -04:00
|
|
|
println!("{} chars", text.chars().count());
|
|
|
|
|
let preview: String = text.chars().take(400).collect();
|
|
|
|
|
println!("{}", preview);
|
|
|
|
|
}
|
2026-10-11 20:32:00 -04:00
|
|
|
Ok(false) => {
|
|
|
|
|
failures += 1;
|
|
|
|
|
println!("UNCLAIMED: no extractor claims {:?}", mime);
|
|
|
|
|
}
|
2026-08-05 18:05:04 -04:00
|
|
|
Err(e) => {
|
|
|
|
|
failures += 1;
|
|
|
|
|
println!("FAILED: {}", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
println!();
|
|
|
|
|
}
|
|
|
|
|
std::process::exit(if failures > 0 { 1 } else { 0 });
|
|
|
|
|
}
|