Skip to content

gachou/media-mime-detect

Repository files navigation

media-mime-detect

NPM version Travis Build Status Coverage Status

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.

Additional file-types

  • video/m2pt: MPEG2-Transport-Stream (used by cameras that record AVHCD-videos)

Installation

npm install media-mime-detect

Usage

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' }

API-reference

License

media-mime-detect is published under the MIT-license. See LICENSE.md for details.

Release-Notes

For release notes, see CHANGELOG.md

Contributing guidelines

See CONTRIBUTING.md.

About

streaming detection of media-files in Node.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published