Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "dart:async" show Future, Stream; | |
| 6 import "dart:convert" show Encoding; | |
| 7 import "loader.dart"; | |
| 8 import "resolve.dart"; | |
| 9 import "../resource.dart" as core; | |
| 10 | |
| 11 /// Default implementation of a generic `Resource` class. | |
| 12 /// | |
| 13 /// Doesn't actually implement any [Resource] class because different platforms | |
| 14 /// currently have different top-level classes, so this class can be considered | |
| 15 /// a mixin or base-class below the actual implementation class. | |
| 16 /// 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.
| |
| 17 /// and make this the default implementation of the top-level `Resource` | |
| 18 /// interface. | |
| 19 /// | |
| 20 /// Requires a loader to be provided. | |
| 21 class Resource { | |
| 22 /// Loading strategy for the resource. | |
| 23 final ResourceLoader _loader; | |
| 24 | |
| 25 /// The URI of the resource. | |
| 26 final _uri; | |
| 27 | |
| 28 const Resource(uri, ResourceLoader loader) | |
| 29 : _uri = uri, _loader = loader; | |
| 30 | |
| 31 Uri get uri => (_uri is String) ? Uri.parse(_uri) : (_uri as Uri); | |
| 32 | |
| 33 Stream<List<int>> openRead() async* { | |
| 34 Uri uri = await _resolvedUri; | |
| 35 yield* _loader.openRead(uri); | |
| 36 } | |
| 37 | |
| 38 Future<List<int>> readAsBytes() async { | |
| 39 Uri uri = await _resolvedUri; | |
| 40 return _loader.readAsBytes(uri); | |
| 41 } | |
| 42 | |
| 43 Future<String> readAsString({Encoding encoding}) async { | |
| 44 Uri uri = await _resolvedUri; | |
| 45 return _loader.readAsString(uri, encoding: encoding); | |
| 46 } | |
| 47 | |
| 48 Future<Uri> get _resolvedUri => resolveUri(uri); | |
| 49 } | |
| OLD | NEW |