Chromium Code Reviews| 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); |
| +} |