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

Unified Diff: lib/src/package_loader.dart

Issue 1612003002: Add browser-compatible version. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Made test run Created 4 years, 11 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 | « lib/src/loader.dart ('k') | lib/src/resolve.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/package_loader.dart
diff --git a/lib/src/package_loader.dart b/lib/src/package_loader.dart
new file mode 100644
index 0000000000000000000000000000000000000000..b834c793a0649b1c6397c985f651505a46ccb872
--- /dev/null
+++ b/lib/src/package_loader.dart
@@ -0,0 +1,31 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. 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" show Future, Stream;
+import "dart:convert" show Encoding;
+
+import "resource_loader.dart";
+import "resolve.dart";
+
+/// Implementation of [ResourceLoader] that accepts relative and package: URIs.
+///
+/// Acts like the `loader` it is provided with except that it resolves
+/// package URIs and relative URI references before loading them.
+///
+/// This class may be useful when you don't want to bother creating a resource
+/// object, and just want to load a resource directly.
+class PackageLoader implements ResourceLoader {
+ final ResourceLoader _loader;
+ const PackageLoader(ResourceLoader loader) : _loader = loader;
+
+ Stream<List<int>> openRead(Uri uri) async* {
+ yield* _loader.openRead(await resolveUri(uri));
+ }
+
+ Future<List<int>> readAsBytes(Uri uri) async =>
+ _loader.readAsBytes(await resolveUri(uri));
+
+ Future<String> readAsString(Uri uri, { Encoding encoding }) async =>
+ _loader.readAsString(await resolveUri(uri), encoding: encoding);
+}
« no previous file with comments | « lib/src/loader.dart ('k') | lib/src/resolve.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698