| Index: pkg/barback/lib/src/asset.dart
|
| diff --git a/pkg/barback/lib/src/asset.dart b/pkg/barback/lib/src/asset.dart
|
| index 636d468886d3d65ca6bccf6354328e0e51f702b8..83def7408156e78863f86359befafeaf503b80f0 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);
|
| +
|
| + 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);
|
|
|
| Future<String> readAsString() => _file.readAsString();
|
| 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);
|
|
|
| Future<String> readAsString() => new Future.value(_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
|
|
|