| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library barback.asset; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 import 'dart:convert'; | |
| 10 | |
| 11 import 'asset_id.dart'; | |
| 12 import 'internal_asset.dart'; | |
| 13 | |
| 14 /// A blob of content. | |
| 15 /// | |
| 16 /// Assets may come from the file system, or as the output of a [Transformer]. | |
| 17 /// They are identified by [AssetId]. | |
| 18 /// | |
| 19 /// Custom implementations of [Asset] are not currently supported. | |
| 20 abstract class Asset { | |
| 21 /// The ID for this asset. | |
| 22 final AssetId id; | |
| 23 | |
| 24 factory Asset.fromBytes(AssetId id, List<int> bytes) => | |
| 25 new BinaryAsset(id, bytes); | |
| 26 | |
| 27 factory Asset.fromFile(AssetId id, File file) => | |
| 28 new FileAsset(id, file.path); | |
| 29 | |
| 30 factory Asset.fromString(AssetId id, String content) => | |
| 31 new StringAsset(id, content); | |
| 32 | |
| 33 factory Asset.fromPath(AssetId id, String path) => | |
| 34 new FileAsset(id, path); | |
| 35 | |
| 36 factory Asset.fromStream(AssetId id, Stream<List<int>> stream) => | |
| 37 new StreamAsset(id, stream); | |
| 38 | |
| 39 /// Returns the contents of the asset as a string. | |
| 40 /// | |
| 41 /// If the asset was created from a [String] the original string is always | |
| 42 /// returned and [encoding] is ignored. Otherwise, the binary data of the | |
| 43 /// asset is decoded using [encoding], which defaults to [UTF8]. | |
| 44 Future<String> readAsString({Encoding encoding}); | |
| 45 | |
| 46 /// Streams the binary contents of the asset. | |
| 47 /// | |
| 48 /// If the asset was created from a [String], this returns its UTF-8 encoding. | |
| 49 Stream<List<int>> read(); | |
| 50 } | |
| OLD | NEW |