Whether
identify file type by file magic numbers.
about magic numbers
- Magic numbers are the first bits of a file which uniquely identify the type of file.
- see details.
Getting start
install
npm install whether
check an image is exactly the given type.
var whether = ; ; // will return boolean // or async way ; // check whether the file content type is matched with the file extension. ; //matched with jpg type, return boolean. // or aync way ; // isValid is an alias ;
plain identify
identify a file with magic numbers. keep in mind the identify is a class method.
var Whether = ; // identify jpg file, will return boolean Whether; // async way Whether;
exts map defines
see the config.js
you can define your map.
// will only overwrite the exist keys var whether = exts: 'ext1': '...' 'ext2': '...' 'ext3': '...' ; // then use these definitions. ; ;
define file type check methods
sometimes, we want to check a file is some kind of file.
eg: whether a file is an image.
define a check method, use an array to tell which exts are included.
// define in config. var whether = defs: isImage: 'png' 'gif' 'jpg' 'bmp' isMS: 'doc' 'ppt' 'xls' ... exts: ... ; // use the defined methods ; // async way ; // define instantly var whether = exts: ext1: '...' ext2: '...' ; whether; // then use ; ;
notice: all the exts used in methods definitions should have defined in the config.exts
details
please see the test files.
license
MIT