Chromium Code Reviews| Index: pkg/barback/lib/src/asset.dart |
| diff --git a/pkg/barback/lib/src/asset.dart b/pkg/barback/lib/src/asset.dart |
| index 2de733fcf1f1b268714b8f3e229fe9824c571cc9..8076971ff8bca2734f6b82b698fa23dff2db6337 100644 |
| --- a/pkg/barback/lib/src/asset.dart |
| +++ b/pkg/barback/lib/src/asset.dart |
| @@ -7,30 +7,38 @@ library barback.asset; |
| import 'dart:async'; |
| import 'dart:io'; |
| +import 'asset_id.dart'; |
| + |
| /// A blob of content. |
| /// |
| /// Assets may come from the file system, or as the output of a [Transformer]. |
| /// They are identified by [AssetId]. |
| abstract class Asset { |
| - factory Asset.fromFile(File file) { |
| - return new _FileAsset(file); |
| + /// The ID for this asset. |
| + final AssetId id; |
| + |
| + Asset._(this.id); |
|
nweiz
2013/07/03 20:08:25
If this is no longer an interface, making this pri
Bob Nystrom
2013/07/03 22:32:11
Changed to public.
|
| + |
| + factory Asset.fromFile(AssetId id, File file) { |
| + return new _FileAsset(id, file); |
| } |
| - factory Asset.fromString(String content) { |
| - return new _StringAsset(content); |
| + factory Asset.fromString(AssetId id, String content) { |
| + return new _StringAsset(id, content); |
| } |
| - factory Asset.fromPath(String path) { |
| - return new _FileAsset(new File(path)); |
| + factory Asset.fromPath(AssetId id, String path) { |
| + return new _FileAsset(id, new File(path)); |
| } |
| // TODO(rnystrom): This prevents users from defining their own |
| // implementations of Asset. Use serialization package instead. |
| factory Asset.deserialize(data) { |
| // TODO(rnystrom): Handle errors. |
| + var id = new AssetId.parse(data[1]); |
| switch (data[0]) { |
| - case "file": return new _FileAsset(new File(data[1])); break; |
| - case "string": return new _StringAsset(data[1]); break; |
| + case "file": return new _FileAsset(id, new File(data[2])); break; |
| + case "string": return new _StringAsset(id, data[2]); break; |
| } |
| } |
| @@ -47,24 +55,26 @@ abstract class Asset { |
| } |
| /// An asset backed by a file on the local file system. |
| -class _FileAsset implements Asset { |
| +class _FileAsset extends Asset { |
| final File _file; |
| - _FileAsset(this._file); |
| + _FileAsset(AssetId id, this._file) |
| + : super._(id); |
| String readAsString() => _file.readAsStringSync(); |
| Stream<List<int>> read() => _file.openRead(); |
| String toString() => 'File "${_file.path}"'; |
| - Object serialize() => ["file", _file.path]; |
| + Object serialize() => ["file", id.serialize(), _file.path]; |
| } |
| /// An asset whose data is stored in a string. |
| // TODO(rnystrom): Have something similar for in-memory binary assets. |
| -class _StringAsset implements Asset { |
| +class _StringAsset extends Asset { |
| final String _contents; |
| - _StringAsset(this._contents); |
| + _StringAsset(AssetId id, this._contents) |
| + : super._(id); |
| String readAsString() => _contents; |
| @@ -83,7 +93,7 @@ class _StringAsset implements Asset { |
| return 'String "$contents"'; |
| } |
| - Object serialize() => ["string", _contents]; |
| + Object serialize() => ["string", id.serialize(), _contents]; |
| String _escape(String string) { |
| return string |