Chromium Code Reviews| Index: pkg/mime/README.md |
| diff --git a/pkg/mime/README.md b/pkg/mime/README.md |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d27f3ce00480fac5ce6004825a23b6751b1c47c6 |
| --- /dev/null |
| +++ b/pkg/mime/README.md |
| @@ -0,0 +1,49 @@ |
| +#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 instances of the `MimeTypeResolver` class is used to determine the |
|
wibling
2015/02/18 13:44:45
NIT: I would not stress that it is the instances o
Søren Gjesse
2015/02/18 14:44:18
Done.
|
| +MIME type for file. It supports both using the extention of the file |
|
wibling
2015/02/18 13:44:46
TYPO: extention -> extension.
Søren Gjesse
2015/02/18 14:44:18
Done.
|
| +name and possibly looking at magic bytes from the begining of the |
|
wibling
2015/02/18 13:44:46
NIT: I would remove possibly. It is implicit in 'I
Søren Gjesse
2015/02/18 14:44:18
Done.
|
| +file. |
| + |
| +There is a builtin instance of `MimeTypeResolver` accessible through |
| +the top level function `lookupMimeType`. This builtin instance have |
|
wibling
2015/02/18 13:44:45
NIT: have -> has
Søren Gjesse
2015/02/18 14:44:18
Done.
|
| +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 instantiating `MimeTypeResolver` |
|
wibling
2015/02/18 13:44:46
NIT: you -> your
NIT: by instantiating ... -> by
Søren Gjesse
2015/02/18 14:44:18
Changed to 'by creating an instance of'
|
| +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 strream of bytes. |
|
wibling
2015/02/18 13:44:45
NIT: strream -> stream
Søren Gjesse
2015/02/18 14:44:18
Done.
|
| + |
| +An example of processing an HTTP request just printing the length of |
| +the content of each part. |
|
wibling
2015/02/18 13:44:46
I would change the above to:
Below is an example
Søren Gjesse
2015/02/18 14:44:18
Done.
|
| + |
| + // 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)) |
|
wibling
2015/02/18 13:44:46
boundary -> _?
Søren Gjesse
2015/02/18 14:44:18
The boundary value is from the variable above.
|
| + .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 |