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
Weekly downloads
23K
decreased by-0.16%
Maintainers
1
Weekly downloads
 
Created
Source

mime-kind License npm

Build Status node Test Coverage bitHound Score

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

Install

$ npm install mime-kind --save

Usage

const fs = require('fs');
const mime = require('mime-kind');

mime('c:/anonim.jpeg'); // -> { ext: 'jpeg', mime: 'image/jpeg' }
mime('.fakeext'); // -> null
mime(fs.createReadStream('./anonim.jpg')); // -> { ext: 'jpeg', mime: 'image/jpeg' }

API

mime(data, [defaultValue])

Returns an object (or null 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 null.
const mime = require('mime-kind');

mime('.fakeext', 'application/octet-stream'); // -> { ext: 'bin', mime: 'application/octet-stream' }
mime('.fakeext', { ext: 'mp4', mime: 'video/mp4' }); // -> { ext: 'mp4', mime: 'video/mp4' }
mime('.fakeext', 'ogg'); // -> { ext: 'ogg', mime: 'audio/ogg' }
// but
mime('.fakeext', 'ogg3'); // -> null
mime('.fakeext', { ext: 'fake', mime: 'fake/fake' }); // -> { ext: 'fake', mime: 'fake/fake' }

License

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

Keywords

FAQs

Package last updated on 31 May 2017

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc