Is Mime
Checks whether a buffer or stream is a valid MIME type.
Checks known byte offsets for
magic numbers.
Examples
Checking streams:
var fs = require('fs')
, isMime = require('is-mime')
, stream = fs.createReadStream(__dirname + '/image.jpg')
isMime.checkStream('image/jpeg', stream)
isMime.checkStream('image/png', stream)
stream.on('mimetype', function(mimetype) {
assert.equal(mimetype, 'image/jpeg')
assert.equal(stream.mimetype, 'image/jpeg')
})
stream.resume()
Checking buffers:
var fs = require('fs')
, isMime = require('is-mime')
fs.readFile(__dirname + '/image.png', function(err, buffer) {
if (err) throw err
assert.ok(isMime.checkBuffer('image/png', buffer))
})
Supported MIME types
- image/png
- image/jpeg
- image/gif
- image/webp
- audio/mpeg (MP3)
- audio/ogg (Vorbis, Opus)
- video/webm
- video/mp4
API
TODO