Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Detect the MIME type of a Buffer, Uint8Array, ArrayBuffer, ReadableStream, file path and file name, with async method.
Detect the MIME type of a Buffer
, Uint8Array
, ArrayBuffer
, ReadableStream
, file path and file name, with async
method.
$ npm install mime-kind --save
const { createReadStream } = require('fs');
const mime = require('mime-kind');
await mime('.fakeext'); // -> null
await mime(createReadStream('./anonim.jpg')); // -> { ext: 'jpeg', mime: 'image/jpeg' }
await mime('c:/anonim.jpeg'); // -> { ext: 'jpeg', mime: 'image/jpeg' }
Returns a Promise
with an object (or null
when no match) with:
ext
- file typemime
- the MIME typeThis methods supports all kind of ReadableStreams
.
Buffer
, Uint8Array
, ArrayBuffer
, ReadableStream
, file path or file name.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');
await mime('.fakeext', 'application/octet-stream'); // -> { ext: 'bin', mime: 'application/octet-stream' }
await mime.async('.fakeext', { ext: 'mp4', mime: 'video/mp4' }); // -> { ext: 'mp4', mime: 'video/mp4' }
await mime.async('.fakeext', 'ogg'); // -> { ext: 'ogg', mime: 'audio/ogg' }
// but
await mime.async('.fakeext', 'ogg3'); // -> null
await mime('.fakeext', { ext: 'fake', mime: 'fake/fake' }); // -> null
With HTTP(S)
streams:
const mime = require('mime-kind');
const { get } = require('https');
const { PassThrough } = require('stream');
const pass = new PassThrough();
get('https://avatars0.githubusercontent.com/u/2401029', res => res.pipe(pass));
await mime(pass); // -> { ext: 'jpg', mime: 'image/jpeg' }
The MIT License (MIT)
Copyright (c) 2015-2022 Alexey Bystrov
FAQs
Detect the MIME type of a Buffer, Uint8Array, ArrayBuffer, ReadableStream, file path and file name, with async method.
The npm package mime-kind receives a total of 24,660 weekly downloads. As such, mime-kind popularity was classified as popular.
We found that mime-kind 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.