feat: add file-forma.rs
This commit is contained in:
38
file-format-rs/src/main.rs
Executable file
38
file-format-rs/src/main.rs
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env runrs
|
||||
|
||||
//! ```cargo
|
||||
//! [dependencies]
|
||||
//! file-format = { version = "0.27.0", features = ["reader"] }
|
||||
//! rust_util = { version = "0.6" }
|
||||
//! ```
|
||||
|
||||
use file_format::FileFormat;
|
||||
use rust_util::{failure_and_exit, success, warning};
|
||||
|
||||
fn main() {
|
||||
let filenames = std::env::args().skip(1).collect::<Vec<_>>();
|
||||
if filenames.is_empty() {
|
||||
failure_and_exit!("There are no filenames!")
|
||||
}
|
||||
for filename in &filenames {
|
||||
let file_format = match FileFormat::from_file(filename) {
|
||||
Ok(file_format) => file_format,
|
||||
Err(e) => {
|
||||
warning!("Read file: {}, failed: {}", filename, e);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
success!("File: {}", filename);
|
||||
println!("Name : {}", file_format.name());
|
||||
if let Some(short_name) = file_format.short_name() {
|
||||
println!("Short name : {}", short_name);
|
||||
}
|
||||
println!("Kind : {:?}", file_format.kind());
|
||||
println!("Extension : {}", file_format.extension());
|
||||
println!("Media type : {}", file_format.media_type());
|
||||
}
|
||||
}
|
||||
|
||||
// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20250531T002509+08:00.MEQCIGgJxc6Zw3eTviQTWg0Q
|
||||
// fTekVUxKIE/Q6W18wlEGleeSAiBGBDCOQbwknbHIxQrb6qe+nfOydjB0ewy4T5fSQQBcBA==
|
||||
Reference in New Issue
Block a user