Index: lib/src/browser/loader.dart |
diff --git a/lib/src/loader.dart b/lib/src/browser/loader.dart |
similarity index 62% |
copy from lib/src/loader.dart |
copy to lib/src/browser/loader.dart |
index b6b4e678247bacd4a2a519afd6767de07fb27407..2c89c504b12d49035656a38745c2346422ff3e81 100644 |
--- a/lib/src/loader.dart |
+++ b/lib/src/browser/loader.dart |
@@ -5,7 +5,8 @@ |
import "dart:async" show Future, Stream; |
import "dart:convert" show Encoding; |
import "dart:isolate" show Isolate; |
-import "io.dart" as io; // TODO: make this import configuration dependent. |
+ |
+import "html_io.dart" as io; |
/// Resource loading strategy. |
/// |
@@ -24,7 +25,7 @@ abstract class ResourceLoader { |
/// (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 const ResourceLoader defaultLoader = const PackageLoader(); |
+ static ResourceLoader get defaultLoader => const DefaultLoader(); |
/// Reads the file located by [uri] as a stream of bytes. |
Stream<List<int>> openRead(Uri uri); |
@@ -44,12 +45,13 @@ abstract class ResourceLoader { |
Future<String> readAsString(Uri uri, { Encoding encoding }); |
} |
-/// Default implementation of [ResourceLoader]. |
+/// Default implementation of [ResourceLoader].. |
/// |
/// Uses the system's available loading functionality to implement the |
/// loading functions. |
/// |
-/// Supports `http:`, `https:`, `file:` and `data:` URIs. |
+/// Supports as many of `http:`, `https:`, `file:` and `data:` URIs as |
+/// possible. |
class DefaultLoader implements ResourceLoader { |
const DefaultLoader(); |
@@ -60,33 +62,3 @@ class DefaultLoader implements ResourceLoader { |
Future<String> readAsString(Uri uri, { Encoding encoding }) => |
io.readAsString(uri, encoding); |
} |
- |
- |
-/// Implementation of [ResourceLoader] that accepts relative and package: URIs. |
-/// |
-/// Like [DefaultLoader] except that it resolves package URIs and relative |
-/// URI references as well. |
-/// |
-/// 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 { |
- const PackageLoader(); |
- |
- Stream<List<int>> openRead(Uri uri) async* { |
- yield* io.readAsStream(await resolveUri(uri)); |
- } |
- |
- Future<List<int>> readAsBytes(Uri uri) async => |
- io.readAsBytes(await resolveUri(uri)); |
- |
- Future<String> readAsString(Uri uri, { Encoding encoding }) async => |
- io.readAsString(await resolveUri(uri), encoding); |
-} |
- |
-/// Helper function for resolving to a non-relative, non-package URI. |
-Future<Uri> resolveUri(Uri uri) async { |
- if (uri.scheme == "package") { |
- return Isolate.resolvePackageUri(uri); |
- } |
- return Uri.base.resolveUri(uri); |
-} |