OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 pub.io; | 6 library pub.io; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import 'dart:collection'; | 9 import 'dart:collection'; |
10 import 'dart:io'; | 10 import 'dart:io'; |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 /// Reads and discards all output from [stream]. Returns a [Future] that | 415 /// Reads and discards all output from [stream]. Returns a [Future] that |
416 /// completes when the stream is closed. | 416 /// completes when the stream is closed. |
417 Future drainStream(Stream stream) { | 417 Future drainStream(Stream stream) { |
418 return stream.fold(null, (x, y) {}); | 418 return stream.fold(null, (x, y) {}); |
419 } | 419 } |
420 | 420 |
421 /// Returns a [EventSink] that pipes all data to [consumer] and a [Future] that | 421 /// Returns a [EventSink] that pipes all data to [consumer] and a [Future] that |
422 /// will succeed when [EventSink] is closed or fail with any errors that occur | 422 /// will succeed when [EventSink] is closed or fail with any errors that occur |
423 /// while writing. | 423 /// while writing. |
424 Pair<EventSink, Future> consumerToSink(StreamConsumer consumer) { | 424 Pair<EventSink, Future> consumerToSink(StreamConsumer consumer) { |
425 var controller = new StreamController(); | 425 var controller = new StreamController(sync: true); |
426 var done = controller.stream.pipe(consumer); | 426 var done = controller.stream.pipe(consumer); |
427 return new Pair<EventSink, Future>(controller.sink, done); | 427 return new Pair<EventSink, Future>(controller.sink, done); |
428 } | 428 } |
429 | 429 |
430 // TODO(nweiz): remove this when issue 7786 is fixed. | 430 // TODO(nweiz): remove this when issue 7786 is fixed. |
431 /// Pipes all data and errors from [stream] into [sink]. When [stream] is done, | 431 /// Pipes all data and errors from [stream] into [sink]. When [stream] is done, |
432 /// the returned [Future] is completed and [sink] is closed if [closeSink] is | 432 /// the returned [Future] is completed and [sink] is closed if [closeSink] is |
433 /// true. | 433 /// true. |
434 /// | 434 /// |
435 /// When an error occurs on [stream], that error is passed to [sink]. If | 435 /// When an error occurs on [stream], that error is passed to [sink]. If |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 /// Create a .tar.gz archive from a list of entries. Each entry can be a | 732 /// Create a .tar.gz archive from a list of entries. Each entry can be a |
733 /// [String], [Directory], or [File] object. The root of the archive is | 733 /// [String], [Directory], or [File] object. The root of the archive is |
734 /// considered to be [baseDir], which defaults to the current working directory. | 734 /// considered to be [baseDir], which defaults to the current working directory. |
735 /// Returns a [ByteStream] that will emit the contents of the archive. | 735 /// Returns a [ByteStream] that will emit the contents of the archive. |
736 ByteStream createTarGz(List contents, {baseDir}) { | 736 ByteStream createTarGz(List contents, {baseDir}) { |
737 var buffer = new StringBuffer(); | 737 var buffer = new StringBuffer(); |
738 buffer.write('Creating .tag.gz stream containing:\n'); | 738 buffer.write('Creating .tag.gz stream containing:\n'); |
739 contents.forEach((file) => buffer.write('$file\n')); | 739 contents.forEach((file) => buffer.write('$file\n')); |
740 log.fine(buffer.toString()); | 740 log.fine(buffer.toString()); |
741 | 741 |
742 var controller = new StreamController<List<int>>(); | 742 var controller = new StreamController<List<int>>(sync: true); |
743 | 743 |
744 if (baseDir == null) baseDir = path.current; | 744 if (baseDir == null) baseDir = path.current; |
745 baseDir = path.absolute(baseDir); | 745 baseDir = path.absolute(baseDir); |
746 contents = contents.map((entry) { | 746 contents = contents.map((entry) { |
747 entry = path.absolute(entry); | 747 entry = path.absolute(entry); |
748 if (!isBeneath(entry, baseDir)) { | 748 if (!isBeneath(entry, baseDir)) { |
749 throw new ArgumentError('Entry $entry is not inside $baseDir.'); | 749 throw new ArgumentError('Entry $entry is not inside $baseDir.'); |
750 } | 750 } |
751 return path.relative(entry, from: baseDir); | 751 return path.relative(entry, from: baseDir); |
752 }).toList(); | 752 }).toList(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 const PubProcessResult(this.stdout, this.stderr, this.exitCode); | 818 const PubProcessResult(this.stdout, this.stderr, this.exitCode); |
819 | 819 |
820 bool get success => exitCode == 0; | 820 bool get success => exitCode == 0; |
821 } | 821 } |
822 | 822 |
823 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. | 823 /// Gets a [Uri] for [uri], which can either already be one, or be a [String]. |
824 Uri _getUri(uri) { | 824 Uri _getUri(uri) { |
825 if (uri is Uri) return uri; | 825 if (uri is Uri) return uri; |
826 return Uri.parse(uri); | 826 return Uri.parse(uri); |
827 } | 827 } |
OLD | NEW |