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

Unified Diff: lib/src/loader.dart

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Created 5 years, 2 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
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);
+}

Powered by Google App Engine
This is Rietveld 408576698