OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of mime; |
6 | 6 |
7 | 7 |
8 /** | 8 /** |
9 * A Mime Multipart class representing each part parsed by | 9 * A Mime Multipart class representing each part parsed by |
10 * [MimeMultipartTransformer]. The data is streamed in as it become available. | 10 * [MimeMultipartTransformer]. The data is streamed in as it become available. |
11 */ | 11 */ |
12 abstract class MimeMultipart extends Stream<List<int>> { | 12 abstract class MimeMultipart extends Stream<List<int>> { |
13 Map<String, String> get headers; | 13 Map<String, String> get headers; |
14 } | 14 } |
15 | 15 |
16 class _MimeMultipart extends MimeMultipart { | 16 class _MimeMultipart extends MimeMultipart { |
17 final Map<String, String> headers; | 17 final Map<String, String> headers; |
18 final Stream<List<int>> _stream; | 18 final Stream<List<int>> _stream; |
19 | 19 |
20 _MimeMultipart(this.headers, this._stream); | 20 _MimeMultipart(this.headers, this._stream); |
21 | 21 |
22 StreamSubscription<List<int>> listen(void onData(List<int> data), | 22 StreamSubscription<List<int>> listen(void onData(List<int> data), |
23 {void onDone(), | 23 {void onDone(), |
24 void onError(error), | 24 void onError(error), |
25 bool cancelOnError}) { | 25 bool cancelOnError}) { |
26 return _stream.listen(onData, | 26 return _stream.listen(onData, |
27 onDone: onDone, | 27 onDone: onDone, |
28 onError: onError, | 28 onError: onError, |
29 cancelOnError: cancelOnError); | 29 cancelOnError: cancelOnError); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
| 33 class _Const { |
| 34 // Bytes for '()<>@,;:\\"/[]?={} \t'. |
| 35 static const SEPARATORS = const [40, 41, 60, 62, 64, 44, 59, 58, 92, 34, 47, |
| 36 91, 93, 63, 61, 123, 125, 32, 9]; |
| 37 } |
| 38 |
| 39 class _CharCode { |
| 40 static const int HT = 9; |
| 41 static const int LF = 10; |
| 42 static const int CR = 13; |
| 43 static const int SP = 32; |
| 44 static const int DASH = 45; |
| 45 static const int COLON = 58; |
| 46 } |
| 47 |
33 /** | 48 /** |
34 * Parser for MIME multipart types of data as described in RFC 2046 | 49 * Parser for MIME multipart types of data as described in RFC 2046 |
35 * section 5.1.1. The data is transformed into [MimeMultipart] objects, each | 50 * section 5.1.1. The data is transformed into [MimeMultipart] objects, each |
36 * of them streaming the multipart data. | 51 * of them streaming the multipart data. |
37 */ | 52 */ |
38 class MimeMultipartTransformer | 53 class MimeMultipartTransformer |
39 implements StreamTransformer<List<int>, MimeMultipart> { | 54 implements StreamTransformer<List<int>, MimeMultipart> { |
40 static const int _START = 0; | 55 static const int _START = 0; |
41 static const int _FIRST_BOUNDARY_ENDING = 111; | 56 static const int _FIRST_BOUNDARY_ENDING = 111; |
42 static const int _FIRST_BOUNDARY_END = 112; | 57 static const int _FIRST_BOUNDARY_END = 112; |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 406 } |
392 | 407 |
393 void _expectWS(int byte) { | 408 void _expectWS(int byte) { |
394 if (byte != _CharCode.SP && byte != _CharCode.HT) { | 409 if (byte != _CharCode.SP && byte != _CharCode.HT) { |
395 throw new MimeMultipartException("Failed to parse multipart mime 2"); | 410 throw new MimeMultipartException("Failed to parse multipart mime 2"); |
396 } | 411 } |
397 } | 412 } |
398 } | 413 } |
399 | 414 |
400 | 415 |
401 class MimeMultipartException implements IOException { | 416 class MimeMultipartException implements Exception { |
402 const MimeMultipartException([String this.message = ""]); | 417 const MimeMultipartException([String this.message = ""]); |
403 String toString() => "MimeMultipartException: $message"; | 418 String toString() => "MimeMultipartException: $message"; |
404 final String message; | 419 final String message; |
405 } | 420 } |
OLD | NEW |