Detect file type from 'Magic' Bytes
npm install stream-signaturejs
const fs = require('fs')
const streamSignature = require('stream-signature')
const signature = new streamSignature()
signature.on('signature', signature => {
console.log(JSON.stringify(signature, null, 2))
})
fs.createReadStream('path/to/file.png')
.pipe(signature)
.pipe(…whatever else you want to do with the data…)
// outputs:
// {
// "mimetype": "image/png",
// "description": "Image encoded in the Portable Network Graphics format",
// "extensions": [
// "png"
// ]
// }
`
#### Changes from buffer-signature
* Converted to a PassThrough stream
* No Dependancies
* Emits 'signature' event as soon file signature is detected
* this event will also be emmited after no signature can be determined with the default application/octet-stream as the mimetype with an aditonal property unknown set to true`