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

Side by Side Diff: utils/pub/io.dart

Issue 11821062: Don't die because we write empty arrays to cURL. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 | « utils/pub/curl_client.dart ('k') | no next file » | 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 /// Helper functionality to make working with IO easier. 5 /// Helper functionality to make working with IO easier.
6 library io; 6 library io;
7 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 592
593 _OutputStreamConsumer(this._outputStream); 593 _OutputStreamConsumer(this._outputStream);
594 594
595 Future consume(Stream<List<int>> stream) { 595 Future consume(Stream<List<int>> stream) {
596 // TODO(nweiz): we have to manually keep track of whether or not the 596 // TODO(nweiz): we have to manually keep track of whether or not the
597 // completer has completed since the output stream could signal an error 597 // completer has completed since the output stream could signal an error
598 // after close() has been called but before it has shut down internally. See 598 // after close() has been called but before it has shut down internally. See
599 // the following TODO. 599 // the following TODO.
600 var completed = false; 600 var completed = false;
601 var completer = new Completer(); 601 var completer = new Completer();
602 stream.listen((data) => _outputStream.write(data), onDone: () { 602 stream.listen((data) {
603 // Writing empty data to a closed stream can cause errors.
604 if (data.isEmpty) return;
605
606 // TODO(nweiz): remove this try/catch when issue 7836 is fixed.
607 try {
608 _outputStream.write(data);
609 } catch (e, stack) {
610 if (!completed) completer.completeError(e, stack);
611 completed = true;
612 }
613 }, onDone: () {
603 _outputStream.close(); 614 _outputStream.close();
604 // TODO(nweiz): wait until _outputStream.onClosed is called once issue 615 // TODO(nweiz): wait until _outputStream.onClosed is called once issue
605 // 7761 is fixed. 616 // 7761 is fixed.
606 if (!completed) completer.complete(null); 617 if (!completed) completer.complete(null);
607 completed = true; 618 completed = true;
608 }); 619 });
609 620
610 _outputStream.onError = (e) { 621 _outputStream.onError = (e) {
611 if (!completed) completer.completeError(e); 622 if (!completed) completer.completeError(e);
612 completed = true; 623 completed = true;
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 Directory _getDirectory(entry) { 1028 Directory _getDirectory(entry) {
1018 if (entry is Directory) return entry; 1029 if (entry is Directory) return entry;
1019 return new Directory(entry); 1030 return new Directory(entry);
1020 } 1031 }
1021 1032
1022 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. 1033 /// Gets a [Uri] for [uri], which can either already be one, or be a [String].
1023 Uri _getUri(uri) { 1034 Uri _getUri(uri) {
1024 if (uri is Uri) return uri; 1035 if (uri is Uri) return uri;
1025 return new Uri.fromString(uri); 1036 return new Uri.fromString(uri);
1026 } 1037 }
OLDNEW
« no previous file with comments | « utils/pub/curl_client.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698