mime-sniffer

0.0.3 • Public • Published

mime-sniffer

A little utility to get the mime-type from binary files.

Unlike mime, mime-sniffer uses magic numbers instead of file extensions to get a more accurate (and less easily faked) mime-type for a given file.

Install

npm install mime-sniffer --save

Usage

var mime = require('mime-sniffer');
mime.lookup('/path/to/file.jpg', function(err, info) {
    console.log(info); // { mime: 'image/jpeg', extension: 'jpg' }
});

You can also pass in a Buffer:

var fs = require('fs');
var mime = require('mime-sniffer');
mime.lookup(fs.readFileSync('/path/to/file.jpg'), function(err, info) {
    console.log(info); // { mime: 'image/jpeg', extension: 'jpg' }
});

Supported files

To see what file types are supported, take a peek in the lib/numbers.js file.

Currently, mime-sniffer supports:

Images

  • gif
  • png
  • jpg
  • webp
  • tiff
  • bmp

Video

  • mp4
  • mov
  • webm

Audio

  • mp3
  • ogg
  • flac
  • wav

Misc

  • pdf

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i mime-sniffer

Weekly Downloads

249

Version

0.0.3

License

MIT

Last publish

Collaborators

  • rosszurowski