mime-db vs content-type vs file-type vs mime vs mime-lookup vs mime-types
Web開発におけるMIMEタイプ管理ライブラリ
mime-dbcontent-typefile-typemimemime-lookupmime-types類似パッケージ:

Web開発におけるMIMEタイプ管理ライブラリ

MIMEタイプ管理ライブラリは、ファイルやデータの種類を識別し、適切な処理を行うために使用されます。これらのライブラリは、HTTPリクエストやレスポンスにおいて、コンテンツの種類を正確に指定するために不可欠です。各ライブラリは異なる機能や特性を持ち、特定のニーズに応じて選択することができます。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
mime-db192,146,6881,224226 kB361年前MIT
content-type60,405,67014310.5 kB63年前MIT
file-type35,216,9814,242132 kB313時間前MIT
mime02,352161 kB16ヶ月前MIT
mime-lookup01-0-MIT
mime-types01,45422.9 kB204ヶ月前MIT

機能比較: mime-db vs content-type vs file-type vs mime vs mime-lookup vs mime-types

MIMEタイプの解析

  • mime-db:

    mime-dbは、MIMEタイプの詳細情報を含むデータベースを提供し、さまざまなMIMEタイプの情報を簡単に取得できます。

  • content-type:

    content-typeは、HTTPヘッダーのContent-Typeを解析し、MIMEタイプを簡単に取得できる機能を提供します。これにより、リクエストやレスポンスの内容を正確に把握することが可能です。

  • file-type:

    file-typeは、バイナリデータを解析してファイルタイプを特定する機能を提供します。ファイルの内容に基づいてタイプを判別するため、拡張子に依存しない正確な結果が得られます。

  • mime:

    mimeは、MIMEタイプを文字列として取得するためのシンプルなAPIを提供し、拡張子からMIMEタイプを簡単に取得できます。

  • mime-lookup:

    mime-lookupは、拡張子からMIMEタイプを迅速に取得するためのシンプルなルックアップ機能を提供します。

  • mime-types:

    mime-typesは、MIMEタイプのリストを管理し、拡張子からMIMEタイプを取得する機能を提供します。

選び方: mime-db vs content-type vs file-type vs mime vs mime-lookup vs mime-types

  • mime-db:

    mime-dbは、MIMEタイプとその詳細情報を包括的に提供するデータベースが必要な場合に選択してください。多くのMIMEタイプとその関連情報を含んでおり、他のライブラリと組み合わせて使用することができます。

  • content-type:

    content-typeは、HTTPヘッダーのContent-Typeを簡単に操作したい場合に選択してください。シンプルなAPIを提供し、MIMEタイプの生成や解析が容易です。

  • file-type:

    file-typeは、バイナリデータからファイルタイプを特定する必要がある場合に選択してください。BufferやStreamをサポートしており、ファイルの拡張子に依存せずに正確なタイプを判別できます。

  • mime:

    mimeは、MIMEタイプの定義と拡張子のマッピングを管理したい場合に選択してください。シンプルで軽量なライブラリで、基本的なMIMEタイプの取得が容易です。

  • mime-lookup:

    mime-lookupは、特定の拡張子からMIMEタイプを取得する必要がある場合に選択してください。シンプルで直感的なAPIを提供し、迅速なルックアップが可能です。

  • mime-types:

    mime-typesは、MIMEタイプのリストを管理し、拡張子からMIMEタイプを取得したり、逆にMIMEタイプから拡張子を取得したりする必要がある場合に選択してください。広範なMIMEタイプのサポートがあり、実用的な機能を提供します。

mime-db のREADME

mime-db

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

This is a large database of mime types and information about them. It consists of a single, public JSON file and does not include any logic, allowing it to remain as un-opinionated as possible with an API. It aggregates data from the following sources:

Installation

npm install mime-db

Database Download

If you intend to use this in a web browser, you can conveniently access the JSON file via jsDelivr, a popular CDN (Content Delivery Network). To ensure stability and compatibility, it is advisable to specify a release tag instead of using the 'master' branch. This is because the JSON file's format might change in future updates, and relying on a specific release tag will prevent potential issues arising from these changes.

https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json

Usage

var db = require('mime-db')

// grab data on .js files
var data = db['application/javascript']

Data Structure

The JSON file is a map lookup for lowercased mime types. Each mime type has the following properties:

  • .source - where the mime type is defined. If not set, it's probably a custom media type.
  • .extensions[] - known extensions associated with this mime type.
  • .compressible - whether a file of this type can be gzipped.
  • .charset - the default charset associated with this type, if any.

If unknown, every property could be undefined.

Note on MIME Type Data and Semver

This package considers the programmatic api as the semver compatibility. This means the MIME type resolution is not considered in the semver bumps. This means that if you want to pin your mime-db data you will need to do it in your application. While this expectation was not set in docs until now, it is how the pacakge operated, so we do not feel this is a breaking change.

Contributing

The primary way to contribute to this database is by updating the data in one of the upstream sources. The database is updated from the upstreams periodically and will pull in any changes.

Registering Media Types

The best way to get new media types included in this library is to register them with the IANA. The community registration procedure is outlined in RFC 6838 section 5. Types registered with the IANA are automatically pulled into this library.

Direct Inclusion

If that is not possible / feasible, they can be added directly here as a "custom" type. To do this, it is required to have a primary source that definitively lists the media type. If an extension is going to be listed as associated with this media type, the source must definitively link the media type and extension as well.

To edit the database, only make PRs against src/custom-types.json or src/custom-suffix.json.

The src/custom-types.json file is a JSON object with the MIME type as the keys and the values being an object with the following keys:

  • compressible - leave out if you don't know, otherwise true/false to indicate whether the data represented by the type is typically compressible.
  • extensions - include an array of file extensions that are associated with the type.
  • notes - human-readable notes about the type, typically what the type is.
  • sources - include an array of URLs of where the MIME type and the associated extensions are sourced from. This needs to be a primary source; links to type aggregating sites and Wikipedia are not acceptable.

To update the build, run npm run build.