Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Unified Diff: sky/sdk/lib/mojo/asset_bundle.dart

Issue 1200463002: Add package:sky/mojo/asset_bundle.dart to wrap mojo:asset_bundle (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..bf77a753ef843932cdb101847c1373f867cce36b
--- /dev/null
+++ b/sky/sdk/lib/mojo/asset_bundle.dart
@@ -0,0 +1,48 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:sky' as sky;
+import 'dart:typed_data';
+
+import 'package:mojo/core.dart' as core;
+import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart';
+
+import 'shell.dart' as shell;
+import 'net/fetch.dart';
+
+Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) {
+ Completer<sky.Image> completer = new Completer();
+ new sky.ImageDecoder(assetData.handle.h, completer.complete);
+ return completer.future;
+}
+
+class AssetBundle {
+ AssetBundle(AssetBundleProxy this._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);
+ }
+
+ AssetBundleProxy _bundle;
+}
+
+Future<AssetBundle> fetchAssetBundle(String url) 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();
+
+ return new AssetBundle(bundle);
+}
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698