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

Side by Side Diff: sdk/lib/io/mime_multipart_parser.dart

Issue 14753009: Make StreamSubscription be the active part of a stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 7 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
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | sdk/lib/mdv_observe_impl/mdv_observe_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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: () {
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
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 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http_parser.dart ('k') | sdk/lib/mdv_observe_impl/mdv_observe_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698