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 /// 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 var completer = new Completer<String>(); | 556 var completer = new Completer<String>(); |
557 var buffer = new StringBuffer(); | 557 var buffer = new StringBuffer(); |
558 stream.onClosed = () => completer.complete(buffer.toString()); | 558 stream.onClosed = () => completer.complete(buffer.toString()); |
559 stream.onData = () => buffer.add(stream.read()); | 559 stream.onData = () => buffer.add(stream.read()); |
560 stream.onError = (e) => completer.completeError(e, stackTrace); | 560 stream.onError = (e) => completer.completeError(e, stackTrace); |
561 return completer.future; | 561 return completer.future; |
562 } | 562 } |
563 | 563 |
564 /// Wraps [stream] in a single-subscription [Stream] that emits the same data. | 564 /// Wraps [stream] in a single-subscription [Stream] that emits the same data. |
565 Stream<List<int>> wrapInputStream(InputStream stream) { | 565 Stream<List<int>> wrapInputStream(InputStream stream) { |
566 var controller = new StreamController.singleSubscription(); | 566 var controller = new StreamController(); |
567 if (stream.closed) return controller..close(); | 567 if (stream.closed) { |
| 568 controller.close(); |
| 569 return controller.stream; |
| 570 } |
568 | 571 |
569 stream.onClosed = controller.close; | 572 stream.onClosed = controller.close; |
570 stream.onData = () => controller.add(stream.read()); | 573 stream.onData = () => controller.add(stream.read()); |
571 stream.onError = (e) => controller.signalError(new AsyncError(e)); | 574 stream.onError = (e) => controller.signalError(new AsyncError(e)); |
572 return controller.stream; | 575 return controller.stream; |
573 } | 576 } |
574 | 577 |
575 // TODO(nweiz): remove this ASAP (issue 7807). | 578 // TODO(nweiz): remove this ASAP (issue 7807). |
576 /// Wraps [stream] in an [InputStream]. | 579 /// Wraps [stream] in an [InputStream]. |
577 InputStream streamToInputStream(Stream<List<int>> stream) { | 580 InputStream streamToInputStream(Stream<List<int>> stream) { |
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 Directory _getDirectory(entry) { | 1031 Directory _getDirectory(entry) { |
1029 if (entry is Directory) return entry; | 1032 if (entry is Directory) return entry; |
1030 return new Directory(entry); | 1033 return new Directory(entry); |
1031 } | 1034 } |
1032 | 1035 |
1033 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1036 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1034 Uri _getUri(uri) { | 1037 Uri _getUri(uri) { |
1035 if (uri is Uri) return uri; | 1038 if (uri is Uri) return uri; |
1036 return new Uri.fromString(uri); | 1039 return new Uri.fromString(uri); |
1037 } | 1040 } |
OLD | NEW |