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 /** | 5 /** |
6 * Helper functionality to make working with IO easier. | 6 * Helper functionality to make working with IO easier. |
7 */ | 7 */ |
8 library io; | 8 library io; |
9 | 9 |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 Future pipeInputToInput(InputStream source, ListInputStream sink) { | 616 Future pipeInputToInput(InputStream source, ListInputStream sink) { |
617 var completer = new Completer(); | 617 var completer = new Completer(); |
618 source.onClosed = () { | 618 source.onClosed = () { |
619 sink.markEndOfStream(); | 619 sink.markEndOfStream(); |
620 completer.complete(null); | 620 completer.complete(null); |
621 }; | 621 }; |
622 source.onData = () { | 622 source.onData = () { |
623 // Even if the sink is closed and we aren't going to do anything with more | 623 // Even if the sink is closed and we aren't going to do anything with more |
624 // data, we still need to drain it from source to work around issue 7218. | 624 // data, we still need to drain it from source to work around issue 7218. |
625 var data = source.read(); | 625 var data = source.read(); |
626 if (!sink.closed) sink.write(data); | 626 |
627 // Force the program to spin the event loop to work around issue 4222 and | |
628 // get sink.closed to be set correctly. | |
Bob Nystrom
2012/12/08 03:51:05
Add some kind of TODO to do something less nasty h
| |
629 sleep(0).then((_) { | |
630 if (!sink.closed) sink.write(data); | |
631 }); | |
627 }; | 632 }; |
628 // TODO(nweiz): propagate this error to the sink. See issue 3657. | 633 // TODO(nweiz): propagate this error to the sink. See issue 3657. |
629 source.onError = (e) { throw e; }; | 634 source.onError = (e) { throw e; }; |
630 return completer.future; | 635 return completer.future; |
631 } | 636 } |
632 | 637 |
633 /** | 638 /** |
634 * Buffers all input from an InputStream and returns it as a future. | 639 * Buffers all input from an InputStream and returns it as a future. |
635 */ | 640 */ |
636 Future<List<int>> consumeInputStream(InputStream stream) { | 641 Future<List<int>> consumeInputStream(InputStream stream) { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1140 return new Directory(entry); | 1145 return new Directory(entry); |
1141 } | 1146 } |
1142 | 1147 |
1143 /** | 1148 /** |
1144 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 1149 * Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
1145 */ | 1150 */ |
1146 Uri _getUri(uri) { | 1151 Uri _getUri(uri) { |
1147 if (uri is Uri) return uri; | 1152 if (uri is Uri) return uri; |
1148 return new Uri.fromString(uri); | 1153 return new Uri.fromString(uri); |
1149 } | 1154 } |
OLD | NEW |