magic_bytes
Guesses the file type using file signatures (magic bytes).
In Rust
Cargo.toml
[dependencies]magic_bytes = "0.1.0"
main.rs
use magic_bytes::guess_extension; let mut f = File::open("foo.pcap")?;let mut buffer = Vec::new(); // read the whole filef.read_to_end(&mut buffer)?; let ext = guess_extension(&buffer); // Extension::Pcap
In JS
npm i magic_bytes
const magic_bytes = import'./pkg'; let myFile = ; // some file as bytesmagic_bytes ;