mime-sniffer
v0.0.3
Published
A mime sniffer that uses file magic numbers rather than unsecure extensions.
Downloads
714
Readme
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
License
MIT