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

Unified Diff: utils/pub/utils.dart

Issue 12191008: Get the pub oauth2 test passing locally. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: utils/pub/utils.dart
diff --git a/utils/pub/utils.dart b/utils/pub/utils.dart
index 7a257d4e16df187fbdfd7b97bc3a18269a109c99..38fa49027fea01d6622cdf17863a4fa91f0545ad 100644
--- a/utils/pub/utils.dart
+++ b/utils/pub/utils.dart
@@ -226,8 +226,8 @@ final RegExp _lineRegexp = new RegExp(r"\r\n|\r|\n");
/// newline is ignored.
Stream<String> streamToLines(Stream<String> stream) {
var buffer = new StringBuffer();
- return stream.transform(new StreamTransformer.from(
- onData: (chunk, sink) {
+ return wrapStream(stream.transform(new StreamTransformer(
+ handleData: (chunk, sink) {
var lines = chunk.split(_lineRegexp);
var leftover = lines.removeLast();
for (var line in lines) {
@@ -240,10 +240,24 @@ Stream<String> streamToLines(Stream<String> stream) {
sink.add(line);
}
buffer.add(leftover);
- }, onDone: (sink) {
+ },
+ handleDone: (sink) {
if (!buffer.isEmpty) sink.add(buffer.toString());
sink.close();
- }));
+ })));
+}
+
+// TODO(nweiz): remove this when issue 8310 is fixed.
+/// Returns a [Stream] identical to [stream], but piped through a new
+/// [StreamController]. This exists to work around issue 8310.
+Stream wrapStream(Stream stream) {
+ var controller = stream.isBroadcast
+ ? new StreamController.broadcast()
+ : new StreamController();
+ stream.listen(controller.add,
+ onError: (e) => controller.signalError(e),
+ onDone: controller.close);
+ return controller.stream;
}
/// Like [Iterable.where], but allows [test] to return [Future]s and uses the

Powered by Google App Engine
This is Rietveld 408576698