mime 0.9.6+2

  • README.md
  • Installing
  • Versions
  • 90

Build Status

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.

print(lookupMimeType('test.html'));  // Will print text/html
print(lookupMimeType('test', [0xFF, 0xD8]));  // Will print image/jpeg
print(lookupMimeType('test.html', [0xFF, 0xD8]));  // Will print 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.
    .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.

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.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  mime: ^0.9.6+2

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:mime/mime.dart';
Version Uploaded Documentation Archive
0.9.6+2 Jul 20, 2018 Go to the documentation of mime 0.9.6+2 Download mime 0.9.6+2 archive
0.9.6+1 May 15, 2018 Go to the documentation of mime 0.9.6+1 Download mime 0.9.6+1 archive
0.9.6 Feb 1, 2018 Go to the documentation of mime 0.9.6 Download mime 0.9.6 archive
0.9.5 Dec 7, 2017 Go to the documentation of mime 0.9.5 Download mime 0.9.5 archive
0.9.4 Oct 25, 2017 Go to the documentation of mime 0.9.4 Download mime 0.9.4 archive
0.9.3 Feb 18, 2015 Go to the documentation of mime 0.9.3 Download mime 0.9.3 archive
0.9.2 Feb 12, 2015 Go to the documentation of mime 0.9.2 Download mime 0.9.2 archive
0.9.1 Dec 3, 2014 Go to the documentation of mime 0.9.1 Download mime 0.9.1 archive
0.9.0+3 May 30, 2014 Go to the documentation of mime 0.9.0+3 Download mime 0.9.0+3 archive
0.9.0+1 May 13, 2014 Go to the documentation of mime 0.9.0+1 Download mime 0.9.0+1 archive

All 52 versions...

Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on May 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.3.1
  • pana: 0.12.16


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:mime/mime.dart.

Health suggestions

Fix lib/src/mime_type.dart. (-4.41 points)

Analysis of lib/src/mime_type.dart reported 9 hints, including:

line 12 col 1: Prefer using /// for doc comments.

line 17 col 1: Prefer using /// for doc comments.

line 32 col 1: Prefer using /// for doc comments.

line 41 col 3: Prefer using /// for doc comments.

line 48 col 3: Prefer using /// for doc comments.

Fix lib/src/mime_multipart_transformer.dart. (-1 points)

Analysis of lib/src/mime_multipart_transformer.dart reported 2 hints:

line 27 col 1: Prefer using /// for doc comments.

line 36 col 3: Prefer using /// for doc comments.

Fix lib/mime.dart. (-0.50 points)

Analysis of lib/mime.dart reported 1 hint:

line 5 col 1: Prefer using /// for doc comments.

Fix lib/src/bound_multipart_stream.dart. (-0.50 points)

Analysis of lib/src/bound_multipart_stream.dart reported 1 hint:

line 36 col 37: Use contains instead of indexOf

Fix lib/src/mime_shared.dart. (-0.50 points)

Analysis of lib/src/mime_shared.dart reported 1 hint:

line 16 col 1: Prefer using /// for doc comments.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and mime.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.20.0 <3.0.0
Dev dependencies
test ^1.2.0