Crates.io | fileidentifier |
lib.rs | fileidentifier |
version | 0.1.1 |
source | src |
created_at | 2022-07-16 10:33:51.242391 |
updated_at | 2022-07-16 16:24:59.97034 |
description | file identifier |
homepage | |
repository | https://github.com/ahmadkhaefi/fileidentifier |
max_upload_size | |
id | 626633 |
size | 255,447 |
This repo is a library for both Rust and Javascript (Node.js). It does not identify files using file extension but using magic number. So It helps you to check files better.
in Rust:
use std::fs;
use fileidentifier::check::{FileFormat, get_file_format, is_png};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let file = fs::read("/usr/bin/whatever")?;
assert_eq!(FileFormat::Script, get_file_format(&file));
// or you can check the file format
let png = fs::read("/file/path/x.png")?;
assert_eq!(true, is_png(&png));
Ok(())
}
in Node.js:
const fi = require('fileidentifier')
let file = fs::readFileSync('/file/path/x.png')
console.log(fi.getFileFormat(file)) // It will print 'png'
// check the file format
console.log(fi.isPng(file)) // It will print true