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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« pkg/mime/CHANGELOG.md ('K') | « pkg/mime/CHANGELOG.md ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #MIME type package
2
3 Package for working with MIME type definitions and for processing
4 streams of MIME multipart media types.
5
6 ##Determining the MIME type for a file
7
8 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.
9 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.
10 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.
11 file.
12
13 There is a builtin instance of `MimeTypeResolver` accessible through
14 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.
15 the most common file name extensions and magic bytes registered.
16
17 print(lookupMimeType('test.html')); // Will print text/html
18 print(lookupMimeType('test', [0xFF, 0xD8])); // Will print image/jpeg
19 print(lookupMimeType('test.html', [0xFF, 0xD8])); // Will print image/jpeg
20
21 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'
22 and adding file name extensions and magic bytes using `addExtension`
23 and `addMagicNumber`.
24
25 ##Processing MIME multipart media types
26
27 The class `MimeMultipartTransformer` is used to process a `Stream` of
28 bytes encoded using a MIME multipart media types encoding. The
29 transformer provides a new `Stream` of `MimeMultipart` objects each of
30 which have the headers and the content of each part. The content of a
31 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.
32
33 An example of processing an HTTP request just printing the length of
34 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.
35
36 // HTTP request with content type multipart/form-data.
37 HttpRequest request = ...;
38 // Determine the boundary form the content type header
39 String boundary = request.headers.contentType.parameters['boundary'];
40
41 // Process the body just calculating the length of each part.
42 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.
43 .map((part) => part.fold(0, (p, d) => p + d))
44 .listen((length) => print('Part with length $length'));
45
46 Take a look at the `HttpBodyHandler` in the [http_server][1] package for
47 handling different content types in a HTTP request.
48
49 [1]: https://pub.dartlang.org/packages/http_server
OLDNEW
« pkg/mime/CHANGELOG.md ('K') | « pkg/mime/CHANGELOG.md ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698