Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-mime

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-mime

Check if stream or buffer is a valid mime-type

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by500%
Maintainers
1
Weekly downloads
 
Created
Source

Is Mime

Build Status

Checks whether a buffer or stream is a valid MIME type. Checks known byte offsets for magic numbers.

Examples

Checking streams:

var fs = require('fs')
  , isMime = require('is-mime')
  , stream = fs.createReadStream(__dirname + '/image.jpg')

// TODO allow passing an array of types
isMime.checkStream('image/jpeg', stream)
isMime.checkStream('image/png', stream)

stream.on('mimetype', function(mimetype) {
	// emitted when it is certain that stream contains type
	// usually after few first `data` events

	// argument is the detected mime type
	assert.equal(mimetype, 'image/jpeg')

	// also sets a `mimetype` property on stream object itself
	assert.equal(stream.mimetype, 'image/jpeg')
})

// use the stream like you would normally
// here we just discard the data
stream.resume()

Checking buffers:

var fs = require('fs')
  , isMime = require('is-mime')

fs.readFile(__dirname + '/image.png', function(err, buffer) {
	if (err) throw err

	// simply pass a type and buffer to `checkBuffer`
	// it will return the type string or null
	assert.ok(isMime.checkBuffer('image/png', buffer))
})

Supported MIME types

  • image/png
  • image/jpeg
  • image/gif
  • image/webp
  • audio/mpeg (MP3)
  • audio/ogg (Vorbis, Opus)
  • video/webm
  • video/mp4

API

TODO

Keywords

FAQs

Package last updated on 18 May 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc