Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
| 116 /// 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.
| |
| 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 Loading... | |
| 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 } |
| OLD | NEW |