mime-kind
![bitHound Score](https://www.bithound.io/github/strikeentco/mime-kind/badges/score.svg)
Detect the mime type of a Buffer, ReadStream, file path and file name.
Install
npm install mime-kind
Usage
var fs = require('fs');
var mime = require('mime-kind');
mime('.somefakeext');
mime(fs.createReadStream('./anonim.jpg'));
API
mime(data, [defaultValue])
Returns an object (or false
when no match) with:
Params:
- data (Buffer|ReadStream|String) -
Buffer
, ReadStream
, file path or file name. - [defaultValue] (String|Object) -
String
or Object
with value which will be returned if no match will be found. If defaultValue
is incorrect returns false
.
var mime = require('mime-kind');
mime('c:/anonim.jpeg');
mime('.somefakeext', 'application/octet-stream');
mime('.somefakeext', {ext: 'mp4', mime: 'video/mp4'});
mime('.somefakeext', 'ogg');
mime('.somefakeext', 'ogg3');
var fs = require('fs');
var mime = require('mime-kind');
function chunkSync(data, length) {
var buf = new Buffer(length);
var fd = fs.openSync(data.path, data.flags);
fs.readSync(fd, buf, 0, length);
fs.closeSync(fd);
return buf;
}
mime(chunkSync({path: './anonim.jpeg', flags: 'r'}, 262);
License
The MIT License (MIT)
Copyright (c) 2015 Alexey Bystrov