Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Unified Diff: pkg/mime/README.md

Issue 936733004: Add README file to the mime package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/mime/CHANGELOG.md ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mime/README.md
diff --git a/pkg/mime/README.md b/pkg/mime/README.md
new file mode 100644
index 0000000000000000000000000000000000000000..dd69358b0172ea5ea44901988f7b41ae0c38f7e9
--- /dev/null
+++ b/pkg/mime/README.md
@@ -0,0 +1,48 @@
+#MIME type package
+
+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 begining 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.
+ 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][1] package for
+handling different content types in a HTTP request.
+
+[1]: https://pub.dartlang.org/packages/http_server
« no previous file with comments | « pkg/mime/CHANGELOG.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698