| Index: sky/sdk/lib/mojo/asset_bundle.dart
|
| diff --git a/sky/sdk/lib/mojo/asset_bundle.dart b/sky/sdk/lib/mojo/asset_bundle.dart
|
| index e0312d144ac75c9e72fd06f18dc86868b6806d51..58a76501c71962042bb73610dbc8d1b15ad99177 100644
|
| --- a/sky/sdk/lib/mojo/asset_bundle.dart
|
| +++ b/sky/sdk/lib/mojo/asset_bundle.dart
|
| @@ -17,31 +17,52 @@ Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) {
|
| return completer.future;
|
| }
|
|
|
| -class AssetBundle {
|
| - AssetBundle(AssetBundleProxy this._bundle);
|
| +abstract class AssetBundle {
|
| + void close();
|
| + Future<sky.Image> fetchImage(String key);
|
| +}
|
|
|
| - void close() {
|
| - _bundle.close();
|
| - _bundle = null;
|
| - }
|
| +class NetworkAssetBundle extends AssetBundle {
|
| + NetworkAssetBundle(Uri base_url) : _base_url = base_url;
|
|
|
| - Future<sky.Image> fetchImage(String path) async {
|
| - core.MojoDataPipeConsumer assetData =
|
| - (await _bundle.ptr.getAsStream(path)).assetData;
|
| + final Uri _base_url;
|
| +
|
| + void close() { }
|
| +
|
| + Future<sky.Image> fetchImage(String name) async {
|
| + Uri url = _base_url.resolve(name);
|
| + core.MojoDataPipeConsumer assetData = (await fetchUrl(url.toString())).body;
|
| return await _decodeImage(assetData);
|
| }
|
| -
|
| - AssetBundleProxy _bundle;
|
| }
|
|
|
| -Future<AssetBundle> fetchAssetBundle(String url) async {
|
| +Future _fetchAndUnpackBundle(String relativeUrl, AssetBundleProxy bundle) async {
|
| core.MojoDataPipeConsumer bundleData = (await fetchUrl(url)).body;
|
| -
|
| AssetUnpackerProxy unpacker = new AssetUnpackerProxy.unbound();
|
| shell.requestService("mojo:asset_bundle", unpacker);
|
| - AssetBundleProxy bundle = new AssetBundleProxy.unbound();
|
| unpacker.ptr.unpackZipStream(bundleData, bundle);
|
| unpacker.close();
|
| +}
|
| +
|
| +class MojoAssetBundle extends AssetBundle {
|
| + MojoAssetBundle(AssetBundleProxy this._bundle);
|
|
|
| - return new AssetBundle(bundle);
|
| + factory MojoAssetBundle.fromNetwork(String relativeUrl) {
|
| + AssetBundleProxy bundle = new AssetBundleProxy.unbound();
|
| + _fetchAndUnpackBundle(relativeUrl, bundle);
|
| + return new AssetBundle(bundle);
|
| + }
|
| +
|
| + AssetBundleProxy _bundle;
|
| +
|
| + void close() {
|
| + _bundle.close();
|
| + _bundle = null;
|
| + }
|
| +
|
| + Future<sky.Image> fetchImage(String name) async {
|
| + core.MojoDataPipeConsumer assetData =
|
| + (await _bundle.ptr.getAsStream(name)).assetData;
|
| + return await _decodeImage(assetData);
|
| + }
|
| }
|
|
|