Name: mime
Owner: Dart
Description: Dart package for working with MIME type definitions and for processing streams of MIME multipart media types.
Created: 2015-02-24 08:52:55.0
Updated: 2018-05-04 09:46:40.0
Pushed: 2018-05-24 18:58:01.0
Homepage: https://pub.dartlang.org/packages/mime
Size: 65
Language: Dart
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Package for working with MIME type definitions and for processing streams of MIME multipart media types.
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.
t(lookupMimeType('test.html')); // Will print text/html
t(lookupMimeType('test', [0xFF, 0xD8])); // Will print image/jpeg
t(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
.
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.
TTP request with content type multipart/form-data.
Request request = ...;
etermine the boundary form the content type header
ng boundary = request.headers.contentType.parameters['boundary'];
rocess the body just calculating the length of each part.
est
.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.
Please file feature requests and bugs at the issue tracker.