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

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

Issue 196983015: Add a [Transform.hasInput] convenience method to Barback. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 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 | « pkg/barback/CHANGELOG.md ('k') | pkg/barback/test/package_graph/transform/transform_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/barback/lib/src/base_transform.dart
diff --git a/pkg/barback/lib/src/base_transform.dart b/pkg/barback/lib/src/base_transform.dart
index ea85f02371552204ce7de7645e17e2ba35d922eb..c0de0f8ac26d5ee171f273cf6e593087aeaa6e3f 100644
--- a/pkg/barback/lib/src/base_transform.dart
+++ b/pkg/barback/lib/src/base_transform.dart
@@ -110,6 +110,17 @@ abstract class BaseTransform {
Stream<List<int>> readInput(AssetId id) =>
futureStream(getInput(id).then((input) => input.read()));
+ /// A convenience method to return whether or not an asset exists.
+ ///
+ /// This is equivalent to calling [getInput] and catching an
+ /// [AssetNotFoundException].
+ Future<bool> hasInput(AssetId id) {
+ return getInput(id).then((_) => true).catchError((error) {
+ if (error is AssetNotFoundException && error.id == id) return false;
+ throw error;
+ });
+ }
+
/// Consume the primary input so that it doesn't get processed by future
/// phases or emitted once processing has finished.
///
« no previous file with comments | « pkg/barback/CHANGELOG.md ('k') | pkg/barback/test/package_graph/transform/transform_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698