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

Unified Diff: lib/src/resource_impl.dart

Issue 1612003002: Add browser-compatible version. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: 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
Index: lib/src/resource_impl.dart
diff --git a/lib/src/resource_impl.dart b/lib/src/resource_impl.dart
new file mode 100644
index 0000000000000000000000000000000000000000..72c99483e12a8352d18997c70e9ded5ac83dc563
--- /dev/null
+++ b/lib/src/resource_impl.dart
@@ -0,0 +1,49 @@
+// 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.
+
+import "dart:async" show Future, Stream;
+import "dart:convert" show Encoding;
+import "loader.dart";
+import "resolve.dart";
+import "../resource.dart" as core;
+
+/// Default implementation of a generic `Resource` class.
+///
+/// Doesn't actually implement any [Resource] class because different platforms
+/// currently have different top-level classes, so this class can be considered
+/// a mixin or base-class below the actual implementation class.
+/// When configuarble imports make it possible, drop the intermediate classes
floitsch 2016/01/21 12:53:57 This shouldn't be a dartdoc.
Lasse Reichstein Nielsen 2016/01/25 10:48:37 Done.
+/// and make this the default implementation of the top-level `Resource`
+/// interface.
+///
+/// Requires a loader to be provided.
+class Resource {
+ /// Loading strategy for the resource.
+ final ResourceLoader _loader;
+
+ /// The URI of the resource.
+ final _uri;
+
+ const Resource(uri, ResourceLoader loader)
+ : _uri = uri, _loader = loader;
+
+ Uri get uri => (_uri is String) ? Uri.parse(_uri) : (_uri as Uri);
+
+ Stream<List<int>> openRead() async* {
+ Uri uri = await _resolvedUri;
+ yield* _loader.openRead(uri);
+ }
+
+ Future<List<int>> readAsBytes() async {
+ Uri uri = await _resolvedUri;
+ return _loader.readAsBytes(uri);
+ }
+
+ Future<String> readAsString({Encoding encoding}) async {
+ Uri uri = await _resolvedUri;
+ return _loader.readAsString(uri, encoding: encoding);
+ }
+
+ Future<Uri> get _resolvedUri => resolveUri(uri);
+}
« lib/src/resource.dart ('K') | « lib/src/resource.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698