| 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 mime; | 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 Function onError, |
| 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 { | 33 class _Const { |
| 34 // Bytes for '()<>@,;:\\"/[]?={} \t'. | 34 // Bytes for '()<>@,;:\\"/[]?={} \t'. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 _index = 0; | 131 _index = 0; |
| 132 _parse(); | 132 _parse(); |
| 133 }, | 133 }, |
| 134 onDone: () { | 134 onDone: () { |
| 135 if (_state != _DONE) { | 135 if (_state != _DONE) { |
| 136 _controller.addError( | 136 _controller.addError( |
| 137 new MimeMultipartException("Bad multipart ending")); | 137 new MimeMultipartException("Bad multipart ending")); |
| 138 } | 138 } |
| 139 _controller.close(); | 139 _controller.close(); |
| 140 }, | 140 }, |
| 141 onError: (error) { | 141 onError: _controller.addError); |
| 142 _controller.addError(error); | |
| 143 }); | |
| 144 }); | 142 }); |
| 145 return _controller.stream; | 143 return _controller.stream; |
| 146 } | 144 } |
| 147 | 145 |
| 148 void _parse() { | 146 void _parse() { |
| 149 // Number of boundary bytes to artificially place before the supplied data. | 147 // Number of boundary bytes to artificially place before the supplied data. |
| 150 int boundaryPrefix = 0; | 148 int boundaryPrefix = 0; |
| 151 // Position where content starts. Will be null if no known content | 149 // Position where content starts. Will be null if no known content |
| 152 // start exists. Will be negative of the content starts in the | 150 // start exists. Will be negative of the content starts in the |
| 153 // boundary prefix. Will be zero or position if the content starts | 151 // boundary prefix. Will be zero or position if the content starts |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 } | 409 } |
| 412 } | 410 } |
| 413 } | 411 } |
| 414 | 412 |
| 415 | 413 |
| 416 class MimeMultipartException implements Exception { | 414 class MimeMultipartException implements Exception { |
| 417 const MimeMultipartException([String this.message = ""]); | 415 const MimeMultipartException([String this.message = ""]); |
| 418 String toString() => "MimeMultipartException: $message"; | 416 String toString() => "MimeMultipartException: $message"; |
| 419 final String message; | 417 final String message; |
| 420 } | 418 } |
| OLD | NEW |