Index: lib/src/loader.dart |
diff --git a/lib/src/loader.dart b/lib/src/loader.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..37e9bd2f02b770d91b1d90406019225399d44b94 |
--- /dev/null |
+++ b/lib/src/loader.dart |
@@ -0,0 +1,43 @@ |
+// Copyright (c) 2015, 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. |
+ |
+library resource.loader; |
+ |
+import "dart:async" show Future, Stream; |
+import "dart:convert" show Encoding; |
+import "io.dart" as io; // TODO: make this import configuration dependent. |
+ |
+/// Resource loading strategy. |
+/// |
+/// An abstraction of the functionality needed to load resources. |
+/// |
+/// An implementation decides which URI schemes it supports. |
+abstract class ResourceLoader { |
+ /// Reads the file located by [uri] as a stream of bytes. |
floitsch
2015/10/13 12:47:50
I wouldn't use the term "file".
|
+ Stream<List<int>> openRead(Uri uri); |
+ |
+ /// Reads the file located by [uri] as a list of bytes. |
+ Future<List<int>> readAsBytes(Uri uri); |
+ |
+ /// Reads the file located by [uri] as a [String]. |
+ /// |
+ /// The file bytes are decoded using [encoding]. |
+ /// If [encoding] is omittted, it defaults to UTF-8. |
floitsch
2015/10/13 12:47:50
omitted
|
+ Future<String> readAsString(Uri uri, { Encoding encoding }); |
+} |
+ |
+/// Default implementation of [ResourceLoader]. |
+/// |
+/// Uses the system's available loading functionality to implement the |
+/// loading functions. |
+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); |
+} |