| 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 /// | 418 /// |
| 419 /// This will automatically append " (y/n)?" to the message, so [message] | 419 /// This will automatically append " (y/n)?" to the message, so [message] |
| 420 /// should just be a fragment like, "Are you sure you want to proceed". | 420 /// should just be a fragment like, "Are you sure you want to proceed". |
| 421 Future<bool> confirm(String message) { | 421 Future<bool> confirm(String message) { |
| 422 log.fine('Showing confirm message: $message'); | 422 log.fine('Showing confirm message: $message'); |
| 423 stdoutSink.add("$message (y/n)? ".charCodes); | 423 stdoutSink.add("$message (y/n)? ".charCodes); |
| 424 return streamFirst(stdinLines) | 424 return streamFirst(stdinLines) |
| 425 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); | 425 .then((line) => new RegExp(r"^[yY]").hasMatch(line)); |
| 426 } | 426 } |
| 427 | 427 |
| 428 /// Reads and discards all output from [inputStream]. Returns a [Future] that |
| 429 /// completes when the stream is closed. |
| 430 Future drainInputStream(InputStream inputStream) { |
| 431 var completer = new Completer(); |
| 432 if (inputStream.closed) { |
| 433 completer.complete(); |
| 434 return completer.future; |
| 435 } |
| 436 |
| 437 inputStream.onClosed = () => completer.complete(); |
| 438 inputStream.onData = inputStream.read; |
| 439 inputStream.onError = (error) => completer.completeError(error); |
| 440 return completer.future; |
| 441 } |
| 442 |
| 428 /// Wraps [stream] in a single-subscription [Stream] that emits the same data. | 443 /// Wraps [stream] in a single-subscription [Stream] that emits the same data. |
| 429 ByteStream wrapInputStream(InputStream stream) { | 444 ByteStream wrapInputStream(InputStream stream) { |
| 430 var controller = new StreamController(); | 445 var controller = new StreamController(); |
| 431 if (stream.closed) { | 446 if (stream.closed) { |
| 432 controller.close(); | 447 controller.close(); |
| 433 return new ByteStream(controller.stream); | 448 return new ByteStream(controller.stream); |
| 434 } | 449 } |
| 435 | 450 |
| 436 stream.onClosed = controller.close; | 451 stream.onClosed = controller.close; |
| 437 stream.onData = () => controller.add(stream.read()); | 452 stream.onData = () => controller.add(stream.read()); |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 Directory _getDirectory(entry) { | 947 Directory _getDirectory(entry) { |
| 933 if (entry is Directory) return entry; | 948 if (entry is Directory) return entry; |
| 934 return new Directory(entry); | 949 return new Directory(entry); |
| 935 } | 950 } |
| 936 | 951 |
| 937 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 952 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
| 938 Uri _getUri(uri) { | 953 Uri _getUri(uri) { |
| 939 if (uri is Uri) return uri; | 954 if (uri is Uri) return uri; |
| 940 return Uri.parse(uri); | 955 return Uri.parse(uri); |
| 941 } | 956 } |
| OLD | NEW |