Through stream for verifying if a stream is a valid image (png, gif 87a/89a/ or jpg)
MIT License
Provides a transform stream to inspect the incoming header of an image to detemine if it's a valid image format.
Currently supports:
const fs = require('fs')
const path = require('path')
const ImageValidatorStream = require('image-validator-stream')
function validateThenCopy (src, dst, cb) {
const ext = path.extname(src)
const ivs = new ImageValidatorStream({ext: ext})
ivs.on('error', function (err) {
err.file = dst
cb(err)
})
const out = fs.createWriteStream(dst).on('end', function () {
cb()
})
fs.createReadStream(src).pipe(ivs).pipe(out)
}
validateThenCopy(path.join(__dirname, 'junk.jpg'), 'awesome.jpg', function (err) {
if (err) {
fs.unlink(err.file, function (err) {
if (err) {
console.log(err)
}
console.log('oh noes!')
})
} else {
console.log('awyiss')
}
})
npm install image-validator-stream
Copyright © 2014 Todd Kennedy, Licensed under the MIT License