https://github.com/toddself/image-validator-stream
https://github.com/toddself/image-validator-stream
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/toddself/image-validator-stream
- Owner: toddself
- License: mit
- Created: 2014-04-10T21:33:12.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2018-08-14T20:18:10.000Z (almost 8 years ago)
- Last Synced: 2025-04-12T16:14:08.563Z (about 1 year ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# image-validator-stream
[](http://travis-ci.org/toddself/image-validator-stream)
Provides a transform stream to inspect the incoming header of an image to detemine if it's a valid image format.
Currently supports:
* jpg
* png
* gif (87a/89a)
## Example
```js
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')
}
})
```
[full example](example/abort-on-bad.js)
## Installation
`npm install image-validator-stream`
## License
Copyright © 2014 Todd Kennedy, Licensed under the [MIT License](LICENSE)