![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
is-mime
Advanced tools
Readme
Checks whether a buffer, stream or file is a valid MIME type. Checks known byte offsets for magic numbers.
Checking buffers:
var fs = require('fs')
, assert = require('assert')
, 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))
// type argument can be an array too
})
Checking files:
var assert = require('assert')
, isMime = require('is-mime')
, types = ['image/jpeg', 'image/png']
isMime.checkFile(types, __dirname + '/image.png')
// returns a Promise for a type string or null
.then(function (mimetype) {
assert.equal(mimetype, 'image/png')
})
Checking streams:
var fs = require('fs')
, assert = require('assert')
, isMime = require('is-mime')
, input, checker
input = fs.createReadStream(__dirname + '/image.jpg')
// checker is a PassThrough stream that emits `mimetype` event
checker = isMime.checkStream(['image/jpeg', 'image/png'])
checker.on('mimetype', function(mimetype) {
// emitted once it is certain that stream contains
// one of the provided types
// argument is the detected mime type
assert.equal(mimetype, 'image/jpeg')
// also sets a `mimetype` property on stream object itself
assert.equal(checker.mimetype, 'image/jpeg')
})
input.pipe(checker)
checker.resume() // discard data
Copy a file and print the detected MIME type:
var fs = require('fs')
, isMime = require('is-mime')
fs.createReadStream(__dirname + '/image.png')
.pipe(
isMime.checkStream([
'image/jpeg',
'image/png',
'image/gif',
])
.on('mimetype', console.log)
)
.pipe(
fs.createWriteStream(__dirname + '/image2.png')
.on('end', function() {
console.log('Copying finished')
})
)
FAQs
Check if stream or buffer is a valid mime-type
The npm package is-mime receives a total of 1 weekly downloads. As such, is-mime popularity was classified as not popular.
We found that is-mime demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.