small library to validate Files by reading each magic number from a file
- Node version 12.x or higher
$ npm install filesig
Simple
const filesig = require('filesig');
const fs = require('fs');
fs.readFile('/home/john/document.pdf', (err, data) => {
if (err) {
console.log(err);
} else {
console.log(filesig.isPdf(data));
}
});
One of
const filesig = require('filesig');
const fs = require('fs');
fs.readFile('/home/john/Capture.PNG', (err, data) => {
if (err) {
console.log(err);
} else {
let valid = filesig.oneOf(data, filesig.is3gp, filesig.isJpeg, filesig.isPng);
console.log(valid);
}
});