1 extern crate content_inspector;
2 
3 use std::env;
4 use std::fs::File;
5 use std::io::{Error, Read};
6 use std::path::Path;
7 use std::process::exit;
8 
9 const MAX_PEEK_SIZE: usize = 1024;
10 
main() -> Result<(), Error>11 fn main() -> Result<(), Error> {
12     let mut args = env::args();
13 
14     if args.len() < 2 {
15         eprintln!("USAGE: inspect FILE [FILE...]");
16         exit(1);
17     }
18 
19     args.next();
20 
21     for filename in args {
22         if !Path::new(&filename).is_file() {
23             continue;
24         }
25 
26         let file = File::open(&filename)?;
27         let mut buffer: Vec<u8> = vec![];
28 
29         file.take(MAX_PEEK_SIZE as u64).read_to_end(&mut buffer)?;
30 
31         let content_type = content_inspector::inspect(&buffer);
32         println!("{}: {}", filename, content_type);
33     }
34 
35     Ok(())
36 }
37