# mime-kind

> Detect the MIME type of a Buffer, Uint8Array, ArrayBuffer, ReadableStream, file path and file name, with async method.

Latest version **4.0.0** (published 2022-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install mime-kind
pnpm add mime-kind
yarn add mime-kind
bun add mime-kind
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2022-10-02 |
| First published | 2015-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 2 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Alexey Bystrov |
| Maintainers | strikeentco |
| Keywords | file, type, types, mime, buffer, stream, read stream, readable stream, detect, sync, async |

## Links

- npm: https://www.npmjs.com/package/mime-kind
- Repository: https://github.com/strikeentco/mime-kind
- Homepage: https://github.com/strikeentco/mime-kind#readme
- Issues: https://github.com/strikeentco/mime-kind/issues
- npm.io page: https://npm.io/package/mime-kind

## Dependencies (2)

- [file-type](https://npm.io/package/file-type.md) ^16.5.4
- [mime-types](https://npm.io/package/mime-types.md) ^2.1.24

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2022-10-02
- 3.0.0 — 2019-08-09
- 2.0.2 — 2017-05-31
- 2.0.1 — 2016-10-24
- 2.0.0 — 2016-09-07
- 1.0.4 — 2016-03-12
- 1.0.3 — 2016-02-19
- 1.0.2 — 2015-09-26
- 1.0.1 — 2015-09-26
- 1.0.0 — 2015-09-26

## README

mime-kind [![License](https://img.shields.io/npm/l/mime-kind.svg)](https://github.com/strikeentco/mime-kind/blob/master/LICENSE) [![npm](https://img.shields.io/npm/v/mime-kind.svg)](https://www.npmjs.com/package/mime-kind)
==========
[![Build Status](https://travis-ci.org/strikeentco/mime-kind.svg)](https://travis-ci.org/strikeentco/mime-kind) [![node](https://img.shields.io/node/v/mime-kind.svg)](https://www.npmjs.com/package/mime-kind) [![Test Coverage](https://api.codeclimate.com/v1/badges/5c3c2bdb323d9132a2f4/test_coverage)](https://codeclimate.com/github/strikeentco/mime-kind/test_coverage)

Detect the MIME type of a `Buffer`, `Uint8Array`, `ArrayBuffer`, `ReadableStream`, file path and file name, with `async` method.

## Install
```sh
$ npm install mime-kind --save
```

## Usage

```js
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' }
```

## API

### mime(input, [defaultValue])
### mime.async(input, [defaultValue])

Returns a `Promise` with an object (or `null` when no match) with:

* `ext` - file type
* `mime` - the [MIME type](http://en.wikipedia.org/wiki/Internet_media_type)

This methods supports all kind of `ReadableStreams`.

### Params:

* **input** (*String|Buffer|Uint8Array|ArrayBuffer|ReadableStream*) - `Buffer`, `Uint8Array`, `ArrayBuffer`, `ReadableStream`, 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`.

```js
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:
```js
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' }
```

## License

The MIT License (MIT)<br/>
Copyright (c) 2015-2022 Alexey Bystrov

---
_Source: https://npm.io/package/mime-kind · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
