p-hatan/ mirror

pub repository

mirror.p-hatan.com

mime

2.1.0

Utilities for handling media (MIME) types, including determining a type from a file extension and file contents.

Cached in Iran · upstream_checksum

Download archive

Readme

package:mime Pub Package package publisher

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'));

Determining file extension by MIME type

The top level function extensionFromMime can be used to determine the file extension of a given MIME type.

print(extensionFromMime('text/html'));  // Prints "html".
print(extensionFromMime('image/jpeg'));  // Prints "jpg".
print(extensionFromMime('application/pdf'));  // Prints "pdf".
Changelog

2.1.0

  • Switched to using the Apache httpd mime.conf table as the source of truth for mime types.

Mime type additions:

  • application/vnd.geogebra.slides
  • font/collection
  • image/jxl
  • image/vnd.dvb.subtitle
  • video/mp2t

Renamed mime types:

  • application/x-font-otf => font/otf
  • application/x-font-ttf => font/ttf
  • application/x-font-woff => font/woff

Removed mime types:

  • model/vnd.mts

Mime types where the default file extension changed:

  • application/inkml+xml, inkml => ink
  • application/octet-stream, so => bin
  • application/onenote, onetoc2 => onetoc
  • application/pgp-signature, sig => asc
  • application/tei+xml, teicorpus => tei
  • application/vnd.adobe.fxp, fxpl => fxp
  • application/vnd.clonk.c4group, c4u => c4g
  • application/vnd.dece.data, uvvf => uvf
  • application/vnd.dece.ttml+xml, uvvt => uvt
  • application/vnd.eszigno3+xml, et3 => es3
  • application/vnd.framemaker, maker => fm
  • application/vnd.geometry-explorer, gre => gex
  • application/vnd.grafeq, gqs => gqf
  • application/vnd.ibm.modcap, listafp => afp
  • application/vnd.iccprofile, icm => icc
  • application/vnd.intercon.formnet, xpx => xpw
  • application/vnd.kde.kpresenter, kpt => kpr
  • application/vnd.kde.kword, kwt => kwd
  • application/vnd.kinar, knp => kne
  • application/vnd.koan, skt => skp
  • application/vnd.ms-project, mpt => mpp
  • application/vnd.palm, pqa => pdb
  • application/vnd.quark.quarkxpress, qxt => qxd
  • application/vnd.simtech-mindmapper, twds => twd
  • application/vnd.stardivision.writer, vor => sdw
  • application/vnd.sus-calendar, susp => sus
  • application/vnd.symbian.install, sisx => sis
  • application/vnd.ufdl, ufdl => ufd
  • application/vnd.visio, vsw => vsd
  • application/vnd.zul, zirz => zir
  • application/x-authorware-bin, x32 => aab
  • application/x-blorb, blorb => blb
  • application/x-cbr, cbz => cbr
  • application/x-director, w3d => dir
  • application/x-font-type1, pfm => pfa
  • application/x-msdownload, msi => exe
  • application/x-pkcs12, pfx => p12
  • application/x-pkcs7-certificates, spc => p7b
  • application/x-zmachine, z8 => z1
  • application/xv+xml, xvml => mxml
  • audio/basic, snd => au
  • audio/mpeg, mpga => mp3
  • audio/vnd.dece.audio, uvva => uva
  • image/tiff, tif => tiff
  • image/vnd.dece.graphic, uvvi => uvi
  • image/x-freehand, fhc => fh
  • message/rfc822, mime => eml
  • model/mesh, silo => msh
  • model/x3d+binary, x3dbz => x3db
  • model/x3d+vrml, x3dvz => x3dv
  • model/x3d+xml, x3dz => x3d
  • text/troff, tr => t
  • text/uri-list, urls => uri
  • text/x-fortran, for => f
  • video/mj2, mjp2 => mj2
  • video/vnd.dece.hd, uvvh => uvh
  • video/vnd.dece.mobile, uvvm => uvm
  • video/vnd.dece.pd, uvvp => uvp
  • video/vnd.dece.sd, uvvs => uvs
  • video/vnd.dece.video, uvvv => uvv
  • video/vnd.uvvu.mp4, uvvu => uvu
  • video/x-ms-asf, asx => asf

2.0.0

  • [Breaking] extensionFromMime(String mimeType) returns null instead of mimeType for an unknown mime type.
  • Update extensionFromMime to return a default extension when a MIME type maps to multiple extensions.

1.0.6

  • Add topics section to pubspec.yaml.
  • Move to dart-lang/tools monorepo.

1.0.5

  • Update video/mp4 mimeType lookup by header bytes.
  • Add image/heic mimeType lookup by header bytes.
  • Add image/heif mimeType lookup by header bytes.
  • Add m4b mimeType lookup by extension.
  • Add text/markdown mimeType lookup by extension.
  • Require Dart 3.2.0.

1.0.4

1.0.3

  • Add application/manifest+json lookup by extension.
  • Add application/toml mimeType lookup by extension.
  • Add audio/aac mimeType lookup by header bytes.
  • Add audio/mpeg mimeType lookup by header bytes.
  • Add audio/ogg mimeType lookup by header bytes.
  • Add audio/weba mimeType lookup by header bytes.
  • Add font/woff2 lookup by extension and header bytes.
  • Add image/avif mimeType lookup by extension.
  • Add image/heic mimeType lookup by extension.
  • Add image/heif mimeType lookup by extension.
  • Change audio/x-aac to audio/aac when detected by extension.

1.0.2

  • Add audio/x-aiff mimeType lookup by header bytes.
  • Add audio/x-flac mimeType lookup by header bytes.
  • Add audio/x-wav mimeType lookup by header bytes.
  • Add audio/mp4 mimeType lookup by file path.

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 extensionFromMime utility function.

0.9.6+3

  • Change the mime type for Dart source from application/dart to text/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 mime
pubspec.yaml
name: mime
version: 2.1.0
description: >-
  Utilities for handling media (MIME) types, including determining a type from
  a file extension and file contents.
repository: https://github.com/dart-lang/tools/tree/main/pkgs/mime
issue_tracker: https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Amime

topics:
  - magic-numbers
  - mime
  - mimetype
  - multipart-form

environment:
  sdk: ^3.2.0

dev_dependencies:
  dart_flutter_team_lints: ^3.0.0
  http: ^1.5.0
  path: ^1.9.0
  test: ^1.16.0

Version history

VersionPublishedArchiveSHA-256
0.6.12013-06-27T19:33:45.263350ZCached6ee181031a4ac16f0c9c9bfd585de1d70f1b6641b2cfcf128089e64a1a624534
0.6.22013-06-28T20:56:35.988740ZCached37225860a0b2cea3292ba280dcbb50ab80c6b5693e90684591c1825ce53ad864
0.6.3+12013-07-09T00:24:36.882900ZCached51368e46f885634e577df8bc924a07c877a680cfadf20f80a07fab1dd7ceffef
0.6.52013-07-16T00:21:21.184600ZCachedafbc7246ab3e611b0c7fc2957547d81876336a95a0315155c2adcb8d7b6ca54c
0.6.62013-07-17T19:42:23.655380ZCached55b19d3b03f077314f344e1bae34bec832bc815d313dabb0cbdac4423d42c3af
0.6.82013-07-19T20:56:09.736070ZCached4346d4c50df919965e17084bad8b146d1c6122b97a8fe5afa5ffb6de34c2cd64
0.6.92013-07-22T15:15:29.719470ZCachedbae5a49971ae562a34aafd8051ee16c50c8292b58fec2543a28ccf86e58a9723
0.6.9+22013-07-24T03:59:14.440920ZCached5714efb2076901b1ac817a7c18d9a49aa88d462fe923d284de80a663506a41ce
0.6.112013-07-25T05:10:15.536610ZCached64c04fe46076a084f2a70466b1ec6c05a8b8ad423aaf49ea715872a5cbff5c1a
0.6.122013-07-26T20:07:08.294850ZCached3bb43d32e230108ec8024da841ddc30308049666529bb7a9c87518ceb84e62d2
0.6.132013-07-30T21:56:41.729360ZCached143d06fbf5d8bd43bf9be9c633124313bce0318be15ebda215037f0bc2b70835
0.6.142013-08-02T16:25:57.127250ZCached99d52a263beee34d565992b6a7555bc7dd0b3149c91ec51457e2e36365ff85da
0.6.15+22013-08-05T22:50:25.942490ZCachedd6916124912bfad09b7fe86634249a5581dea08072f961707538a48f9af6f0b9
0.6.15+32013-08-06T20:13:33.923030ZCachede2c6130fde60bac3cfc51299e8dc281a8a25ad98d6f15ac68794bb32c7b66c54
0.6.172013-08-10T17:35:58.798620ZCached41e642af929612d66be9387fd3dd4f5d458b8b8587ee917cf29493814290fc44
0.6.17+22013-08-12T22:22:36.750740ZCached661b8f3587a3fd072d49b86780020a84c237c6bc7e53d737810056996ea2ddac
0.6.192013-08-19T16:11:26.885240ZCached1e4683de1d883085e00017f4e9d93263fc41787bae4d48e95659ee369613100d
0.6.20+12013-08-22T18:19:54.973590ZCachedd56338d0fa45c84e2727ef5b2092102a71f46969a3ed41e510fc6b98664914ce
0.6.21+32013-08-26T17:43:32.542790ZCachedaa71af46569ae14b34c54cd57a9ccd9e01eca134ab409021cc2e59d5af163c4d
0.7.02013-08-28T19:29:34.863320ZCachedfe60b88ed6b250f59bb1e01f8f829bbbfe3955bdefc2d16f8e596d2e95772ba7
0.7.12013-09-03T15:52:53.334760ZCacheddaa8ac3b76bfe02bef146542dda00838521cf85ba600dc978f26056634ba06de
0.7.22013-09-06T15:51:59.989340ZCachedfdf1939970852d5ccb79584f47c105b55dd3361936965f6e8ae8d2ec9c9176f3
0.7.2+12013-09-08T15:48:00.055170ZCached42d150ed2401421e40167c956654f09f2b33a4149a60fa55d08dbf098fbc79c3
0.7.3+12013-09-16T15:44:48.121610ZCachedbe42b0ed632168c7a87e72a510665769bf4aab4e8b3f4bff3159db20b4a11b05
0.7.42013-09-18T03:04:27.236690ZCached5c20131a25fb4a14a762f65b7b3243458ccbec09fc8f6583776e5f8f378f08d9
0.7.52013-09-21T00:42:44.445390ZCached36874b6f0edc074243f7fc5e6a5583d2e06db25b9a8fc8ce5e02eacb3839c931
0.7.62013-09-27T14:58:15.246910ZCached97788e5c35ba4386c2db17e74cc4ccd972b598fa87a7352976525b2dd78b7ceb
0.7.6+42013-10-01T23:49:19.862410ZCachede2210cfc74591b88501ccf311c86b36e01bbe5885e7cc517ea039988aaf1cb51
0.8.02013-10-03T16:28:12.322070ZCached044bd754e39f7fc0c7219d1b802d3da7acb1328a76a295729915a7b5e769838e
0.8.12013-10-04T21:54:53.488950ZCached31abab3267a32dc387808be5d36f81ec48e942b3ec0dff3859bfd6d124e198ee
0.8.22013-10-14T21:42:38.071070ZCached88b22305cfccdf274536da49c69fb5e66fe420048d8458dcd55f71c85bf36ab6
0.8.32013-10-17T16:01:06.826190ZCached2ccce8f63001b8eb09a2fba2190cbd3ef585defb2847c1a27fce1161d87dd3ce
0.8.42013-10-19T21:09:14.659460ZCached4c250db5422f27a35fc17f182423f4cc1bacaeb8acc249530b23396efd23a43b
0.8.52013-10-21T15:50:57.908780ZCachedea20982b8a21173aab90dfa3ecdfeb66e6b379331dc8931664398994569bb47f
0.8.62013-10-24T08:19:39.812590ZCached8ddf0ad1586715cc542566810d1ec19a3df926c03b5a1582c23ec1144044aecc
0.8.72013-10-28T14:34:08.602650ZCached2b3b6be4dda0924a3201082077c51b93d72587f2343414479d32cea21cb9679a
0.8.82013-10-30T03:29:55.009800ZCachedc9d6fc8274fc9b398262da177bec0754cacc9659cc988a488894c5fe44968e1e
0.8.92013-10-31T15:16:19.429980ZCached3a1749da3dd52a959fbecac28d07164d98c8d4da1a0747f539d8d1357e3175e7
0.8.102013-11-01T19:23:39.000260ZCached6ca11b69b12ff29609ebe76ac441bb7dc0cfac38527f0bb65afcf0b068b1ecc5
0.8.10+32013-11-04T16:49:40.150690ZCacheda6d6bcd704f72525d68f5dd0895617d9a293ae738f14c7e3e524410a8c1f64eb
0.8.10+42013-11-05T16:05:50.108110ZCached67386eb03fdec74c0dce26204f0d7513050899515ec8ae3259f44ed9fec65563
0.9.02013-11-06T19:32:08.050300ZCached99486ac41cea50a4fbc6fb4ee349e52707be50c85f6ffcee9db77c49ef018035
0.9.0+12014-05-13T18:24:51.661850ZCached06dbd318f03a4adabd9dde52859ae2fda9f20be2d87472d06ae12d0dc7ac7667
0.9.0+32014-05-30T17:40:42.439720ZCached5e426baa255a9ad32a57e02dd95ed02c66c40e8f7d6e1aa4b109b54024a0db4f
0.9.12014-12-03T18:53:31.012810ZCached751e254ee14a8f2fa5dc52a06415ab15cb2212b88ed7d278f88651c88d401e59
0.9.22015-02-12T13:54:57.737040ZCached2419e768ae65a51d4b401a5cd4a88cb830477b8842370a2c62449a5d4336de1b
0.9.32015-02-18T14:46:26.477820ZCached6f2da7f8ae179b624f8e14cb36761868452761d6af287f86dc9cc5632e947d49
0.9.42017-10-25T17:37:49.202461ZCachedf1fd96443f6d7f5b7813fa314334c54bec634427f6eca00b73de0351a28e6c30
0.9.52017-12-07T23:08:23.406761ZCachedd51ed8b1b3493100f62f8eaf883d0b7c10098a75ce1947fb2b2755b2378d9a78
0.9.62018-02-01T21:00:10.709102ZCached2ad7238cb3b28d9dce47589276c4c0c21efa751fd50e32797ffeb746dc8abc29
0.9.6+12018-05-15T20:27:57.183088ZCached89748db1ed225d232b8eaa82a365b92f5cf27858cda1db4ff151c2d6d428ac9f
0.9.6+22018-07-20T21:44:33.107005ZCachedc2d2eb570ca85d3429026f2b1b3a4791489e9480c043f0c9dce789c37472144c
0.9.6+32019-05-29T19:04:38.377048ZCached502904712fde940e05c73737450fcfc1f3bb8fa4dab6e69c54e1b558d4ca5ad9
0.9.72020-08-11T03:03:05.393755ZCached5041f313f4e30fbd70dee7c0403785a4ee270f75830f590e5983960fddf743e4
1.0.0-nullsafety.02020-12-08T21:24:14.773412ZCached0782700d8abb2d86cac41b5fee30897f029a58ee1199ca7c3207695979a33522
1.0.02021-02-05T19:05:20.814565ZCacheda7a98ea7f366e2cc9d2b20873815aebec5e2bc124fe0da9d3f7f59b0625ea180
1.0.12021-10-18T14:16:05.870392ZCachedfd5f81041e6a9fc9b9d7fa2cb8a01123f9f5d5d49136e06cb9dc7d33689529f4
1.0.22022-05-02T20:47:14.136138ZCacheddab22e92b41aa1255ea90ddc4bc2feaf35544fd0728e209638cad041a6e3928a
1.0.32022-11-29T21:03:19.720158ZCached52e38f7e1143ef39daf532117d6b8f8f617bf4bcd6044ed8c29040d20d269630
1.0.42023-01-12T00:48:25.596638ZCachede4ff8e8564c03f255408decd16e7899da1733852a9110a58fe6d1b817684a63e
1.0.52024-01-24T22:13:10.934726ZCached2e123074287cc9fd6c09de8336dae606d1ddb88d9ac47358826db698c176a1f2
1.0.62024-08-26T16:13:38.589265ZCached801fd0b26f14a4a58ccb09d5892c3fbdeff209594300a542492cf13fba9d247a
2.0.02024-09-30T17:12:15.400930ZCached41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6
2.1.02026-08-28T20:42:27.296992ZCachedbd47de35f07e27267e69c8c8b22edf9473bfee170a60d60fcc93730c5144b7f6

Dependencies

No direct dependencies declared.