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 dart.io; |
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. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 void _resumeStream() { | 94 void _resumeStream() { |
95 _subscription.resume(); | 95 _subscription.resume(); |
96 } | 96 } |
97 | 97 |
98 void _pauseStream() { | 98 void _pauseStream() { |
99 _subscription.pause(); | 99 _subscription.pause(); |
100 } | 100 } |
101 | 101 |
102 Stream<MimeMultipart> bind(Stream<List<int>> stream) { | 102 Stream<MimeMultipart> bind(Stream<List<int>> stream) { |
103 _controller = new StreamController( | 103 _controller = new StreamController( |
104 onPause: () { | 104 onPause: _pauseStream, |
105 _pauseStream(); | 105 onResume:_resumeStream, |
106 }, | 106 onCancel: () { |
floitsch
2013/05/24 15:53:17
add comment, that we need a closure, because _subs
| |
107 onResume: () { | 107 _subscription.cancel(); |
108 _resumeStream(); | |
109 }, | 108 }, |
110 onListen: () { | 109 onListen: () { |
111 _subscription = stream.listen( | 110 _subscription = stream.listen( |
112 (data) { | 111 (data) { |
113 assert(_buffer == null); | 112 assert(_buffer == null); |
114 _pauseStream(); | 113 _pauseStream(); |
115 _buffer = data; | 114 _buffer = data; |
116 _index = 0; | 115 _index = 0; |
117 _parse(); | 116 _parse(); |
118 }, | 117 }, |
119 onDone: () { | 118 onDone: () { |
120 if (_state != _DONE) { | 119 if (_state != _DONE) { |
121 _controller.addError( | 120 _controller.addError( |
122 new MimeMultipartException("Bad multipart ending")); | 121 new MimeMultipartException("Bad multipart ending")); |
123 } | 122 } |
124 _controller.close(); | 123 _controller.close(); |
125 }, | 124 }, |
126 onError: (error) { | 125 onError: (error) { |
127 _controller.addError(error); | 126 _controller.addError(error); |
128 }); | 127 }); |
129 }, | |
130 onCancel: () { | |
131 _subscription.cancel(); | |
132 }); | 128 }); |
133 return _controller.stream; | 129 return _controller.stream; |
134 } | 130 } |
135 | 131 |
136 void _parse() { | 132 void _parse() { |
137 // Number of boundary bytes to artificially place before the supplied data. | 133 // Number of boundary bytes to artificially place before the supplied data. |
138 int boundaryPrefix = 0; | 134 int boundaryPrefix = 0; |
139 // Position where content starts. Will be null if no known content | 135 // Position where content starts. Will be null if no known content |
140 // start exists. Will be negative of the content starts in the | 136 // start exists. Will be negative of the content starts in the |
141 // boundary prefix. Will be zero or position if the content starts | 137 // boundary prefix. Will be zero or position if the content starts |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
398 } | 394 } |
399 } | 395 } |
400 } | 396 } |
401 | 397 |
402 | 398 |
403 class MimeMultipartException implements Exception { | 399 class MimeMultipartException implements Exception { |
404 const MimeMultipartException([String this.message = ""]); | 400 const MimeMultipartException([String this.message = ""]); |
405 String toString() => "MimeMultipartException: $message"; | 401 String toString() => "MimeMultipartException: $message"; |
406 final String message; | 402 final String message; |
407 } | 403 } |
OLD | NEW |