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

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart

Issue 29343004: Support all Transform methods on ForeignTransform. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/transformer/can_use_read_input_as_string_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
diff --git a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
index cbd444d24f1bed9b772620ad93a3b1e68b7b6a12..141d83b4c81b59b7b2cbd192a4e0fac21eaba344 100644
--- a/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
+++ b/sdk/lib/_internal/pub/lib/src/barback/load_transformers.dart
@@ -19,8 +19,8 @@ import 'server.dart';
/// A Dart script to run in an isolate.
///
-/// This script serializes one or more transformers defined in a Dart library and
-/// marhsals calls to and from them with the host isolate.
+/// This script serializes one or more transformers defined in a Dart library
+/// and marshals calls to and from them with the host isolate.
const _TRANSFORMER_ISOLATE = """
import 'dart:async';
import 'dart:isolate';
@@ -116,6 +116,14 @@ class ForeignTransform implements Transform {
})).then(_deserializeAsset);
}
+ Future<String> readInputAsString(AssetId id, {Encoding encoding}) {
+ if (encoding == null) encoding = UTF8;
+ return getInput(id).then((input) => input.readAsString(encoding: encoding));
+ }
+
+ Stream<List<int>> readInput(AssetId id) =>
+ _futureStream(getInput(id).then((input) => input.read()));
+
void addOutput(Asset output) {
_port.send({
'type': 'addOutput',
@@ -335,6 +343,23 @@ String getErrorMessage(error) {
return error.toString();
}
}
+
+/// Returns a buffered stream that will emit the same values as the stream
+/// returned by [future] once [future] completes. If [future] completes to an
+/// error, the return value will emit that error and then close.
+Stream _futureStream(Future<Stream> future) {
+ var controller = new StreamController(sync: true);
+ future.then((stream) {
+ stream.listen(
+ controller.add,
+ onError: controller.addError,
+ onDone: controller.close);
+ }).catchError((e, stackTrace) {
+ controller.addError(e, stackTrace);
+ controller.close();
+ });
+ return controller.stream;
+}
""";
/// Load and return all transformers and groups from the library identified by
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/transformer/can_use_read_input_as_string_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698