From 067f76b5ff96f5d05f5111a36cf753a5a9b1eeda Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 31 May 2025 00:26:48 +0800 Subject: [PATCH] feat: add file-forma.rs --- file-format-rs/Cargo.lock | 216 +++++++++++++++++++++++++++++++++++++ file-format-rs/Cargo.toml | 8 ++ file-format-rs/src/main.rs | 38 +++++++ file-meta.txt | 1 + script-meta-v2.json | 8 ++ script-meta.json | 5 + 6 files changed, 276 insertions(+) create mode 100644 file-format-rs/Cargo.lock create mode 100644 file-format-rs/Cargo.toml create mode 100755 file-format-rs/src/main.rs diff --git a/file-format-rs/Cargo.lock b/file-format-rs/Cargo.lock new file mode 100644 index 0000000..a3613bd --- /dev/null +++ b/file-format-rs/Cargo.lock @@ -0,0 +1,216 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bitflags" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "file-format" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ff8badf6e72ff15e42c9ade15d01375837173b17d10c228ab41d821082619db" + +[[package]] +name = "file-format-rs" +version = "0.1.0" +dependencies = [ + "file-format", + "rust_util", +] + +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags", + "libc", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "rust_util" +version = "0.6.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bca5d3493eb29d08dc76ee784a78723fe366fec5dfe67ab37da9d50fb868f7c" +dependencies = [ + "lazy_static", + "libc", + "term", + "term_size", +] + +[[package]] +name = "rustversion" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + +[[package]] +name = "term_size" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/file-format-rs/Cargo.toml b/file-format-rs/Cargo.toml new file mode 100644 index 0000000..011910d --- /dev/null +++ b/file-format-rs/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "file-format-rs" +version = "0.1.0" +edition = "2024" + +[dependencies] +file-format = { version = "0.27.0", features = ["reader"] } +rust_util = "0.6.47" diff --git a/file-format-rs/src/main.rs b/file-format-rs/src/main.rs new file mode 100755 index 0000000..12d300c --- /dev/null +++ b/file-format-rs/src/main.rs @@ -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::>(); + 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== diff --git a/file-meta.txt b/file-meta.txt index d37258a..1b1c5e0 100644 --- a/file-meta.txt +++ b/file-meta.txt @@ -3,6 +3,7 @@ commit-msg-rs current-time-rs decrypt-rs derparse-rs +file-format-rs makepassword-rs myip-rs osssendfile-rs diff --git a/script-meta-v2.json b/script-meta-v2.json index edba4fc..8de6be9 100644 --- a/script-meta-v2.json +++ b/script-meta-v2.json @@ -39,6 +39,14 @@ "publish_time": 1737272563312, "update_time": 1737647377228 }, + "file-format.rs": { + "script_name": "file-format.rs", + "script_length": 1274, + "script_sha256": "f65c800169293e8e1a3caa56e4d5833aae34f4e81f2b0c5a011e1dd277a71789", + "script_full_url": "https://git.hatter.ink/rust-scripts/scriptbase/raw/branch/main/file-format-rs/src/main.rs", + "publish_time": 1748622382967, + "update_time": 1748622382967 + }, "helloworld.rs": { "script_name": "helloworld.rs", "script_length": 225, diff --git a/script-meta.json b/script-meta.json index 3bcaa38..66d7b56 100644 --- a/script-meta.json +++ b/script-meta.json @@ -24,6 +24,11 @@ "script_length": 7529, "script_sha256": "c05c8a17be4d25ab899d81bb2c4407af143a49d2b40c26dbb44d43974f20aa64" }, + "file-format-rs": { + "script_name": "file-format-rs", + "script_length": 1274, + "script_sha256": "f65c800169293e8e1a3caa56e4d5833aae34f4e81f2b0c5a011e1dd277a71789" + }, "makepassword-rs": { "script_name": "makepassword-rs", "script_length": 2127,