| Index: sdk/lib/_internal/compiler/js_lib/core_patch.dart
|
| diff --git a/sdk/lib/_internal/compiler/js_lib/core_patch.dart b/sdk/lib/_internal/compiler/js_lib/core_patch.dart
|
| index d42f9a854e1d7be99076861688d9a6eb6cab4d9f..84147e1b165fa9280573e8ba0214648249a916a3 100644
|
| --- a/sdk/lib/_internal/compiler/js_lib/core_patch.dart
|
| +++ b/sdk/lib/_internal/compiler/js_lib/core_patch.dart
|
| @@ -508,3 +508,75 @@ class Uri {
|
| throw new UnsupportedError("'Uri.base' is not supported");
|
| }
|
| }
|
| +
|
| +@patch
|
| +class Resource {
|
| + @patch
|
| + const factory Resource(String uri) = _Resource;
|
| +}
|
| +
|
| +Uri _resolvePackageUri(Uri packageUri) {
|
| + assert(packageUri.scheme == "package");
|
| + if (packageUri.hasAuthority) {
|
| + throw new ArgumentError("Package-URI must not have a host: $packageUri");
|
| + }
|
| + var resolved = Uri.base.resolve("packages/${packageUri.path}");
|
| + return resolved;
|
| +}
|
| +
|
| +patch class Resource {
|
| + /* patch */ const factory Resource(String uri) = _Resource;
|
| +}
|
| +
|
| +class _Resource implements Resource {
|
| + final String _location;
|
| +
|
| + /* patch */ const _Resource(String uri) : _location = uri;
|
| +
|
| + Uri get uri => Uri.base.resolve(_location);
|
| +
|
| + Stream<List<int>> openRead() {
|
| + Uri uri = this.uri;
|
| + if (uri.scheme == "package") {
|
| + uri = _resolvePackageUri(uri);
|
| + }
|
| + if (uri.scheme == "http" || uri.scheme == "https") {
|
| + return _readAsStream(uri);
|
| + }
|
| + throw new StateError("Unable to find resource, unknown scheme: $_location");
|
| + }
|
| +
|
| + Future<List<int>> readAsBytes() {
|
| + Uri uri = this.uri;
|
| + if (uri.scheme == "package") {
|
| + uri = _resolvePackageUri(uri);
|
| + }
|
| + if (uri.scheme == "http" || uri.scheme == "https") {
|
| + return _readAsBytes(uri);
|
| + }
|
| + throw new StateError("Unable to find resource, unknown scheme: $_location");
|
| + }
|
| +
|
| + Future<String> readAsString({Encoding encoding: UTF8}) {
|
| + Uri uri = this.uri;
|
| + if (uri.scheme == "package") {
|
| + uri = _resolvePackageUri(uri);
|
| + }
|
| + if (uri.scheme == "http" || uri.scheme == "https") {
|
| + return _readAsString(uri);
|
| + }
|
| + throw new StateError("Unable to find resource, unknown scheme: $_location");
|
| + }
|
| +
|
| + Stream<List<int> _readAsStream(Uri uri) {
|
| + throw new Uinmplemented("Streaming bytes via HTTP");
|
| + }
|
| +
|
| + Future<List<int>> _readAsBytes(Uri uri) {
|
| + throw new Uinmplemented("Reading bytes via HTTP");
|
| + }
|
| +
|
| + Future<String> _readAsString(Uri uri) {
|
| + throw new Uinmplemented("Reading string via HTTP");
|
| + }
|
| +}
|
|
|