Socket
Socket
Sign inDemoInstall

mime-kind

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mime-kind

Detect the mime type of a Buffer, ReadStream, file path and file name.


Version published
Maintainers
1
Created
Source

mime-kind

Build Status License npm Test Coverage bitHound Score

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'); // false
mime(fs.createReadStream('./anonim.jpg')); // {ext: 'jpeg', mime: 'image/jpeg'}

API

mime(data, [defaultValue])

Returns an object (or false when no match) with:

  • ext - file type
  • mime - the MIME type

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'); // {ext: 'jpeg', mime: 'image/jpeg'}

mime('.somefakeext', 'application/octet-stream'); // {ext: 'bin', mime: 'application/octet-stream'}
mime('.somefakeext', {ext: 'mp4', mime: 'video/mp4'}); // {ext: 'mp4', mime: 'video/mp4'}
mime('.somefakeext', 'ogg'); // {ext: 'ogg', mime: 'audio/ogg'}
//but
mime('.somefakeext', 'ogg3'); // false
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); // {ext: 'jpeg', mime: 'image/jpeg'}

License

The MIT License (MIT)
Copyright (c) 2015 Alexey Bystrov

Keywords

FAQs

Package last updated on 26 Sep 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc