streaming detection of media-files in Node.js
This package uses stream-mmmagic to sniff for magic-bytes on a stream without interupting the
stream. In fact, this package uses stream-mmmagic
directly with a single change:
It ships with a custom magic
-file that contains patterns for mime-types that are not detected
by the current default magic
-file.
video/m2pt
: MPEG2-Transport-Stream (used by cameras that record AVHCD-videos)
npm install media-mime-detect
The following example demonstrates how to use this module:
var fs = require('fs')
var detect = require('media-mime-detect')
detect(fs.createReadStream('prinz-georg-garten.jpg'), function (err, mime, stream) {
if (err) throw err
console.log(mime)
// Here is the place to decide what should happen with the stream
// based on its mime-type
stream.pipe(fs.createWriteStream('prinz-georg-garten2.jpg'))
})
This will generate the following output
{ type: 'image/jpeg', encoding: 'binary' }
media-mime-detect
is published under the MIT-license.
See LICENSE.md for details.
For release notes, see CHANGELOG.md
See CONTRIBUTING.md.