pub repository
mirror.p-hatan.commime
1.0.1Utilities for handling media (MIME) types, including determining a type from a file extension and file contents.
Readme
Package for working with MIME type definitions and for processing streams of MIME multipart media types.
Determining the MIME type for a file
The MimeTypeResolver class can be used to determine the MIME type of
a file. It supports both using the extension of the file name and
looking at magic bytes from the beginning of the file.
There is a builtin instance of MimeTypeResolver accessible through
the top level function lookupMimeType. This builtin instance has
the most common file name extensions and magic bytes registered.
import 'package:mime/mime.dart';
void main() {
print(lookupMimeType('test.html'));
// text/html
print(lookupMimeType('test', headerBytes: [0xFF, 0xD8]));
// image/jpeg
print(lookupMimeType('test.html', headerBytes: [0xFF, 0xD8]));
// image/jpeg
}
You can build you own resolver by creating an instance of
MimeTypeResolver and adding file name extensions and magic bytes
using addExtension and addMagicNumber.
Processing MIME multipart media types
The class MimeMultipartTransformer is used to process a Stream of
bytes encoded using a MIME multipart media types encoding. The
transformer provides a new Stream of MimeMultipart objects each of
which have the headers and the content of each part. The content of a
part is provided as a stream of bytes.
Below is an example showing how to process an HTTP request and print the length of the content of each part.
// HTTP request with content type multipart/form-data.
HttpRequest request = ...;
// Determine the boundary form the content type header
String boundary = request.headers.contentType.parameters['boundary'];
// Process the body just calculating the length of each part.
request
.transform(new MimeMultipartTransformer(boundary))
.map((part) => part.fold(0, (p, d) => p + d))
.listen((length) => print('Part with length $length'));
Take a look at the HttpBodyHandler in the http_server
package for handling different content types in an HTTP request.
Features and bugs
Please file feature requests and bugs at the issue tracker.
Changelog
1.0.1
- Add image/webp mimeType lookup by header bytes.
1.0.0
- Stable null safety release.
1.0.0-nullsafety.0
- Update to null safety.
0.9.7
- Add
extensionFromMimeutility function.
0.9.6+3
- Change the mime type for Dart source from
application/darttotext/x-dart. - Add example.
- Fix links and code in README.
0.9.6+2
- Set max SDK version to
<3.0.0, and adjust other dependencies.
0.9.6+1
- Stop using deprecated constants from the SDK.
0.9.6
-
Updates to support Dart 2.0 core library changes (wave 2.2). See issue 31847 for details.
0.9.5
- Add support for the WebAssembly format.
0.9.4
-
Updated Dart SDK requirement to
>= 1.8.3 <2.0.0 -
Strong-mode clean.
-
Added support for glTF text and binary formats.
0.9.3
- Fixed erroneous behavior for listening and when pausing/resuming stream of parts.
0.9.2
- Fixed erroneous behavior when pausing/canceling stream of parts but already listened to one part.
0.9.1
- Handle parsing of MIME multipart content with no parts.
Installing
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.com
flutter pub add mimepubspec.yaml
name: mime
version: 1.0.1
description: >-
Utilities for handling media (MIME) types, including determining a type from
a file extension and file contents.
homepage: https://github.com/dart-lang/mime
environment:
sdk: '>=2.12.0 <3.0.0'
dev_dependencies:
lints: ^1.0.0
test: ^1.16.0
Version history
| Version | Published | Archive | SHA-256 |
|---|---|---|---|
| 0.6.1 | 2013-06-27T19:33:45.263350Z | Download | 6ee181031a4ac16f0c9c9bfd585de1d70f1b6641b2cfcf128089e64a1a624534 |
| 0.6.2 | 2013-06-28T20:56:35.988740Z | Download | 37225860a0b2cea3292ba280dcbb50ab80c6b5693e90684591c1825ce53ad864 |
| 0.6.3+1 | 2013-07-09T00:24:36.882900Z | Download | 51368e46f885634e577df8bc924a07c877a680cfadf20f80a07fab1dd7ceffef |
| 0.6.5 | 2013-07-16T00:21:21.184600Z | Download | afbc7246ab3e611b0c7fc2957547d81876336a95a0315155c2adcb8d7b6ca54c |
| 0.6.6 | 2013-07-17T19:42:23.655380Z | Download | 55b19d3b03f077314f344e1bae34bec832bc815d313dabb0cbdac4423d42c3af |
| 0.6.8 | 2013-07-19T20:56:09.736070Z | Download | 4346d4c50df919965e17084bad8b146d1c6122b97a8fe5afa5ffb6de34c2cd64 |
| 0.6.9 | 2013-07-22T15:15:29.719470Z | Download | bae5a49971ae562a34aafd8051ee16c50c8292b58fec2543a28ccf86e58a9723 |
| 0.6.9+2 | 2013-07-24T03:59:14.440920Z | Download | 5714efb2076901b1ac817a7c18d9a49aa88d462fe923d284de80a663506a41ce |
| 0.6.11 | 2013-07-25T05:10:15.536610Z | Download | 64c04fe46076a084f2a70466b1ec6c05a8b8ad423aaf49ea715872a5cbff5c1a |
| 0.6.12 | 2013-07-26T20:07:08.294850Z | Download | 3bb43d32e230108ec8024da841ddc30308049666529bb7a9c87518ceb84e62d2 |
| 0.6.13 | 2013-07-30T21:56:41.729360Z | Download | 143d06fbf5d8bd43bf9be9c633124313bce0318be15ebda215037f0bc2b70835 |
| 0.6.14 | 2013-08-02T16:25:57.127250Z | Download | 99d52a263beee34d565992b6a7555bc7dd0b3149c91ec51457e2e36365ff85da |
| 0.6.15+2 | 2013-08-05T22:50:25.942490Z | Download | d6916124912bfad09b7fe86634249a5581dea08072f961707538a48f9af6f0b9 |
| 0.6.15+3 | 2013-08-06T20:13:33.923030Z | Download | e2c6130fde60bac3cfc51299e8dc281a8a25ad98d6f15ac68794bb32c7b66c54 |
| 0.6.17 | 2013-08-10T17:35:58.798620Z | Download | 41e642af929612d66be9387fd3dd4f5d458b8b8587ee917cf29493814290fc44 |
| 0.6.17+2 | 2013-08-12T22:22:36.750740Z | Download | 661b8f3587a3fd072d49b86780020a84c237c6bc7e53d737810056996ea2ddac |
| 0.6.19 | 2013-08-19T16:11:26.885240Z | Download | 1e4683de1d883085e00017f4e9d93263fc41787bae4d48e95659ee369613100d |
| 0.6.20+1 | 2013-08-22T18:19:54.973590Z | Download | d56338d0fa45c84e2727ef5b2092102a71f46969a3ed41e510fc6b98664914ce |
| 0.6.21+3 | 2013-08-26T17:43:32.542790Z | Download | aa71af46569ae14b34c54cd57a9ccd9e01eca134ab409021cc2e59d5af163c4d |
| 0.7.0 | 2013-08-28T19:29:34.863320Z | Download | fe60b88ed6b250f59bb1e01f8f829bbbfe3955bdefc2d16f8e596d2e95772ba7 |
| 0.7.1 | 2013-09-03T15:52:53.334760Z | Download | daa8ac3b76bfe02bef146542dda00838521cf85ba600dc978f26056634ba06de |
| 0.7.2 | 2013-09-06T15:51:59.989340Z | Download | fdf1939970852d5ccb79584f47c105b55dd3361936965f6e8ae8d2ec9c9176f3 |
| 0.7.2+1 | 2013-09-08T15:48:00.055170Z | Download | 42d150ed2401421e40167c956654f09f2b33a4149a60fa55d08dbf098fbc79c3 |
| 0.7.3+1 | 2013-09-16T15:44:48.121610Z | Download | be42b0ed632168c7a87e72a510665769bf4aab4e8b3f4bff3159db20b4a11b05 |
| 0.7.4 | 2013-09-18T03:04:27.236690Z | Download | 5c20131a25fb4a14a762f65b7b3243458ccbec09fc8f6583776e5f8f378f08d9 |
| 0.7.5 | 2013-09-21T00:42:44.445390Z | Download | 36874b6f0edc074243f7fc5e6a5583d2e06db25b9a8fc8ce5e02eacb3839c931 |
| 0.7.6 | 2013-09-27T14:58:15.246910Z | Download | 97788e5c35ba4386c2db17e74cc4ccd972b598fa87a7352976525b2dd78b7ceb |
| 0.7.6+4 | 2013-10-01T23:49:19.862410Z | Download | e2210cfc74591b88501ccf311c86b36e01bbe5885e7cc517ea039988aaf1cb51 |
| 0.8.0 | 2013-10-03T16:28:12.322070Z | Download | 044bd754e39f7fc0c7219d1b802d3da7acb1328a76a295729915a7b5e769838e |
| 0.8.1 | 2013-10-04T21:54:53.488950Z | Download | 31abab3267a32dc387808be5d36f81ec48e942b3ec0dff3859bfd6d124e198ee |
| 0.8.2 | 2013-10-14T21:42:38.071070Z | Download | 88b22305cfccdf274536da49c69fb5e66fe420048d8458dcd55f71c85bf36ab6 |
| 0.8.3 | 2013-10-17T16:01:06.826190Z | Download | 2ccce8f63001b8eb09a2fba2190cbd3ef585defb2847c1a27fce1161d87dd3ce |
| 0.8.4 | 2013-10-19T21:09:14.659460Z | Download | 4c250db5422f27a35fc17f182423f4cc1bacaeb8acc249530b23396efd23a43b |
| 0.8.5 | 2013-10-21T15:50:57.908780Z | Download | ea20982b8a21173aab90dfa3ecdfeb66e6b379331dc8931664398994569bb47f |
| 0.8.6 | 2013-10-24T08:19:39.812590Z | Download | 8ddf0ad1586715cc542566810d1ec19a3df926c03b5a1582c23ec1144044aecc |
| 0.8.7 | 2013-10-28T14:34:08.602650Z | Download | 2b3b6be4dda0924a3201082077c51b93d72587f2343414479d32cea21cb9679a |
| 0.8.8 | 2013-10-30T03:29:55.009800Z | Download | c9d6fc8274fc9b398262da177bec0754cacc9659cc988a488894c5fe44968e1e |
| 0.8.9 | 2013-10-31T15:16:19.429980Z | Download | 3a1749da3dd52a959fbecac28d07164d98c8d4da1a0747f539d8d1357e3175e7 |
| 0.8.10 | 2013-11-01T19:23:39.000260Z | Download | 6ca11b69b12ff29609ebe76ac441bb7dc0cfac38527f0bb65afcf0b068b1ecc5 |
| 0.8.10+3 | 2013-11-04T16:49:40.150690Z | Download | a6d6bcd704f72525d68f5dd0895617d9a293ae738f14c7e3e524410a8c1f64eb |
| 0.8.10+4 | 2013-11-05T16:05:50.108110Z | Download | 67386eb03fdec74c0dce26204f0d7513050899515ec8ae3259f44ed9fec65563 |
| 0.9.0 | 2013-11-06T19:32:08.050300Z | Download | 99486ac41cea50a4fbc6fb4ee349e52707be50c85f6ffcee9db77c49ef018035 |
| 0.9.0+1 | 2014-05-13T18:24:51.661850Z | Download | 06dbd318f03a4adabd9dde52859ae2fda9f20be2d87472d06ae12d0dc7ac7667 |
| 0.9.0+3 | 2014-05-30T17:40:42.439720Z | Download | 5e426baa255a9ad32a57e02dd95ed02c66c40e8f7d6e1aa4b109b54024a0db4f |
| 0.9.1 | 2014-12-03T18:53:31.012810Z | Download | 751e254ee14a8f2fa5dc52a06415ab15cb2212b88ed7d278f88651c88d401e59 |
| 0.9.2 | 2015-02-12T13:54:57.737040Z | Download | 2419e768ae65a51d4b401a5cd4a88cb830477b8842370a2c62449a5d4336de1b |
| 0.9.3 | 2015-02-18T14:46:26.477820Z | Download | 6f2da7f8ae179b624f8e14cb36761868452761d6af287f86dc9cc5632e947d49 |
| 0.9.4 | 2017-10-25T17:37:49.202461Z | Download | f1fd96443f6d7f5b7813fa314334c54bec634427f6eca00b73de0351a28e6c30 |
| 0.9.5 | 2017-12-07T23:08:23.406761Z | Download | d51ed8b1b3493100f62f8eaf883d0b7c10098a75ce1947fb2b2755b2378d9a78 |
| 0.9.6 | 2018-02-01T21:00:10.709102Z | Download | 2ad7238cb3b28d9dce47589276c4c0c21efa751fd50e32797ffeb746dc8abc29 |
| 0.9.6+1 | 2018-05-15T20:27:57.183088Z | Download | 89748db1ed225d232b8eaa82a365b92f5cf27858cda1db4ff151c2d6d428ac9f |
| 0.9.6+2 | 2018-07-20T21:44:33.107005Z | Download | c2d2eb570ca85d3429026f2b1b3a4791489e9480c043f0c9dce789c37472144c |
| 0.9.6+3 | 2019-05-29T19:04:38.377048Z | Download | 502904712fde940e05c73737450fcfc1f3bb8fa4dab6e69c54e1b558d4ca5ad9 |
| 0.9.7 | 2020-08-11T03:03:05.393755Z | Download | 5041f313f4e30fbd70dee7c0403785a4ee270f75830f590e5983960fddf743e4 |
| 1.0.0-nullsafety.0 | 2020-12-08T21:24:14.773412Z | Download | 0782700d8abb2d86cac41b5fee30897f029a58ee1199ca7c3207695979a33522 |
| 1.0.0 | 2021-02-05T19:05:20.814565Z | Download | a7a98ea7f366e2cc9d2b20873815aebec5e2bc124fe0da9d3f7f59b0625ea180 |
| 1.0.1 | 2021-10-18T14:16:05.870392Z | Download | fd5f81041e6a9fc9b9d7fa2cb8a01123f9f5d5d49136e06cb9dc7d33689529f4 |
| 1.0.2 | 2022-05-02T20:47:14.136138Z | Download | dab22e92b41aa1255ea90ddc4bc2feaf35544fd0728e209638cad041a6e3928a |
| 1.0.3 | 2022-11-29T21:03:19.720158Z | Download | 52e38f7e1143ef39daf532117d6b8f8f617bf4bcd6044ed8c29040d20d269630 |
| 1.0.4 | 2023-01-12T00:48:25.596638Z | Download | e4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e |
| 1.0.5 | 2024-01-24T22:13:10.934726Z | Download | 2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2 |
| 1.0.6 | 2024-08-26T16:13:38.589265Z | Download | 801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a |
| 2.0.0 | 2024-09-30T17:12:15.400930Z | Download | 41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6 |
| 2.1.0 | 2026-08-28T20:42:27.296992Z | Download | bd47de35f07e27267e69c8c8b22edf9473bfee170a60d60fcc93730c5144b7f6 |
Dependencies
No direct dependencies declared.