Chromium Code Reviews| 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..d21f9e54c4fd271ed753eb2be18e8963146cff47 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]. |
|
Bob Nystrom
2014/03/14 21:07:58
Nit: but put the "an" on the previous line.
nweiz
2014/03/14 21:53:56
Done.
|
| + 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. |
| /// |