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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library barback.base_transform; 5 library barback.base_transform;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'asset.dart'; 10 import 'asset.dart';
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 /// A convenience method to the contents of the input with [id]. 103 /// A convenience method to the contents of the input with [id].
104 /// 104 ///
105 /// This is equivalent to calling [getInput] followed by [Asset.read]. 105 /// This is equivalent to calling [getInput] followed by [Asset.read].
106 /// 106 ///
107 /// If the asset was created from a [String], this returns its UTF-8 encoding. 107 /// If the asset was created from a [String], this returns its UTF-8 encoding.
108 /// 108 ///
109 /// If an input with [id] cannot be found, throws an [AssetNotFoundException]. 109 /// If an input with [id] cannot be found, throws an [AssetNotFoundException].
110 Stream<List<int>> readInput(AssetId id) => 110 Stream<List<int>> readInput(AssetId id) =>
111 futureStream(getInput(id).then((input) => input.read())); 111 futureStream(getInput(id).then((input) => input.read()));
112 112
113 /// A convenience method to return whether or not an asset exists.
114 ///
115 /// This is equivalent to calling [getInput] and catching an
116 /// [AssetNotFoundException].
117 Future<bool> hasInput(AssetId id) {
118 return getInput(id).then((_) => true).catchError((error) {
119 if (error is AssetNotFoundException && error.id == id) return false;
120 throw error;
121 });
122 }
123
113 /// Consume the primary input so that it doesn't get processed by future 124 /// Consume the primary input so that it doesn't get processed by future
114 /// phases or emitted once processing has finished. 125 /// phases or emitted once processing has finished.
115 /// 126 ///
116 /// Normally the primary input will automatically be forwarded unless the 127 /// Normally the primary input will automatically be forwarded unless the
117 /// transformer overwrites it by emitting an input with the same id. This 128 /// transformer overwrites it by emitting an input with the same id. This
118 /// allows the transformer to tell barback not to forward the primary input 129 /// allows the transformer to tell barback not to forward the primary input
119 /// even if it's not overwritten. 130 /// even if it's not overwritten.
120 void consumePrimary() { 131 void consumePrimary() {
121 _consumePrimary = true; 132 _consumePrimary = true;
122 } 133 }
(...skipping 20 matching lines...) Expand all
143 154
144 /// Notifies the [BaseTransform] that the transformation has finished being 155 /// Notifies the [BaseTransform] that the transformation has finished being
145 /// applied. 156 /// applied.
146 /// 157 ///
147 /// This will close any streams and release any resources that were allocated 158 /// This will close any streams and release any resources that were allocated
148 /// for the duration of the transformation. 159 /// for the duration of the transformation.
149 void close() { 160 void close() {
150 transform._onLogController.close(); 161 transform._onLogController.close();
151 } 162 }
152 } 163 }
OLDNEW
« 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