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

Unified Diff: pkg/barback/lib/src/transform.dart

Issue 23543005: Make Transform a little more pleasant to use: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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
Index: pkg/barback/lib/src/transform.dart
diff --git a/pkg/barback/lib/src/transform.dart b/pkg/barback/lib/src/transform.dart
index d5d717696ff041f72d7077628ad224e3a5a2099a..d8e960f7205acbddab261f879a764098ec9412ed 100644
--- a/pkg/barback/lib/src/transform.dart
+++ b/pkg/barback/lib/src/transform.dart
@@ -5,6 +5,7 @@
library barback.transform;
import 'dart:async';
+import 'dart:convert';
import 'asset.dart';
import 'asset_id.dart';
@@ -34,7 +35,10 @@ class Transform {
final AssetSet _outputs;
- /// Gets the ID of the primary input for this transformation.
+ /// A logger so that the [Transformer] can report build details.
+ TransformLogger get logger => _logger;
+
+ /// Gets the primary input asset.
///
/// While a transformation can use multiple input assets, one must be a
/// special "primary" asset. This will be the "entrypoint" or "main" input
@@ -43,13 +47,10 @@ class Transform {
/// For example, with a dart2js transform, the primary input would be the
/// entrypoint Dart file. All of the other Dart files that that imports
/// would be secondary inputs.
- AssetId get primaryId => _node.primary.id;
-
- /// A logger so that the [Transformer] can report build details.
- TransformLogger get logger => _logger;
-
- /// Gets the asset for the primary input.
- Future<Asset> get primaryInput => getInput(primaryId);
+ Asset get primaryInput {
+ assert(_node.primary.state == AssetState.AVAILABLE);
nweiz 2013/08/28 19:29:43 This shouldn't be an assertion. It's expected to f
Bob Nystrom 2013/08/28 20:51:27 Done.
+ return _node.primary.asset;
+ }
Transform._(this._node, this._outputs);
@@ -59,6 +60,26 @@ class Transform {
/// [AssetNotFoundException].
Future<Asset> getInput(AssetId id) => _node.getInput(id);
+ /// A convenience method to the contents of the input with [id] as a string.
+ ///
+ /// This is equivalent to `getInput().readAsString()`.
nweiz 2013/08/28 19:29:43 `getInput().readAsString()` is a little confusing,
Bob Nystrom 2013/08/28 20:51:27 Reworded a bit. I didn't want to do the full async
+ ///
+ /// If the asset was created from a [String] the original string is always
+ /// returned and [encoding] is ignored. Otherwise, the binary data of the
+ /// asset is decoded using [encoding], which defaults to [UTF8].
+ Future<String> readInputAsString(AssetId id, {Encoding encoding}) {
+ if (encoding == null) encoding = UTF8;
Siggi Cherem (dart-lang) 2013/08/28 00:12:30 why not use "encoding: UTF8" as default value abov
Bob Nystrom 2013/08/28 19:11:34 If you do that, passing an explicit null will over
+ return getInput(id).then((input) => input.readAsString(encoding: encoding));
+ }
+
+ /// A convenience method to the contents of the input with [id].
+ ///
+ /// This is equivalent to `getInput().read()`.
+ ///
+ /// If the asset was created from a [String], this returns its UTF-8 encoding.
+ Future<List<int>> readInput(AssetId id) =>
+ getInput(id).then((input) => input.read());
nweiz 2013/08/28 19:29:43 [Asset.read] returns a Stream<List<int>>, not a Fu
Bob Nystrom 2013/08/28 20:51:27 Done.
+
/// Stores [output] as the output created by this transformation.
///
/// A transformation can output as many assets as it wants.
« no previous file with comments | « no previous file | pkg/barback/test/transformer/check_content.dart » ('j') | pkg/barback/test/transformer/mock.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698