0.1.1 • Published 2 years ago

fileidentifier v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

fileidentifier

This repo is a library for both Rust and Javascript (Node.js). It identify does not identify files using file extension but using magic number. So It helps you to check files better.

Installation

  • For Rust, you can install it from crates.io
  • For Node.js, It is available in npm

How to use

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 a 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 a file format

    console.log(fi.isPng(file)) // It will print true