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

Unified Diff: lib/src/browser/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/browser/html_io.dart ('k') | lib/src/browser/resource.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/browser/loader.dart
diff --git a/lib/src/browser/loader.dart b/lib/src/browser/loader.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0ecaf67dcde1199fad5779436b8790fea504a069
--- /dev/null
+++ b/lib/src/browser/loader.dart
@@ -0,0 +1,55 @@
+// 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" as base;
+import "../package_loader.dart"as base;
+import "html_io.dart" as io;
+
+/// Resource loading strategy.
+///
+/// An abstraction of the functionality needed to load resources.
+///
+/// Implementations of this interface decide which URI schemes they support.
+abstract class ResourceLoader implements base.ResourceLoader {
+ /// A resource loader that can load as many of the following URI
+ /// schemes as are supported by the platform:
+ /// * file
+ /// * http
+ /// * https
+ /// * data
+ /// * package
+ ///
+ /// (For example, file: URIs are not supported in the browser).
+ /// Relative URI references are accepted - they are resolved against
+ /// [Uri.base] before being loaded.
+ static ResourceLoader get defaultLoader =>
+ const PackageLoader(const DefaultLoader());
+}
+
+/// Default implementation of [ResourceLoader]..
+///
+/// Uses the system's available loading functionality to implement the
+/// loading functions.
+///
+/// Supports as many of `http:`, `https:`, `file:` and `data:` URIs as
+/// possible.
+class DefaultLoader implements ResourceLoader {
+ const DefaultLoader();
+
+ Stream<List<int>> openRead(Uri uri) => io.readAsStream(uri);
+
+ Future<List<int>> readAsBytes(Uri uri) => io.readAsBytes(uri);
+
+ Future<String> readAsString(Uri uri, {Encoding encoding}) =>
+ io.readAsString(uri, encoding);
+}
+
+// A loader that implements base.PackageLoader *and* ResourceLoader from this
+// file.
+class PackageLoader extends base.PackageLoader implements ResourceLoader {
+ const PackageLoader(ResourceLoader loader) : super(loader);
+}
« no previous file with comments | « lib/src/browser/html_io.dart ('k') | lib/src/browser/resource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698