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

Side by Side Diff: lib/src/io/loader.dart

Issue 1612003002: Add browser-compatible version. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Made test run 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 unified diff | Download patch
« no previous file with comments | « lib/src/io/io.dart ('k') | lib/src/io/resource.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, 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
8 import "../resource_loader.dart" as base;
9 import "../package_loader.dart"as base;
10 import "io.dart" as io;
11
12 /// Resource loading strategy.
13 ///
14 /// An abstraction of the functionality needed to load resources.
15 ///
16 /// Implementations of this interface decide which URI schemes they support.
17 abstract class ResourceLoader implements base.ResourceLoader {
18 /// A resource loader that can load as many of the following URI
19 /// schemes as are supported by the platform:
20 /// * file
21 /// * http
22 /// * https
23 /// * data
24 /// * package
25 ///
26 /// (For example, file: URIs are not supported in the browser).
27 /// Relative URI references are accepted - they are resolved against
28 /// [Uri.base] before being loaded.
29 static ResourceLoader get defaultLoader =>
30 const PackageLoader(const DefaultLoader());
31 }
32
33 /// Default implementation of [ResourceLoader]..
34 ///
35 /// Uses the system's available loading functionality to implement the
36 /// loading functions.
37 ///
38 /// Supports as many of `http:`, `https:`, `file:` and `data:` URIs as
39 /// possible.
40 class DefaultLoader implements ResourceLoader {
41 const DefaultLoader();
42
43 Stream<List<int>> openRead(Uri uri) => io.readAsStream(uri);
44
45 Future<List<int>> readAsBytes(Uri uri) => io.readAsBytes(uri);
46
47 Future<String> readAsString(Uri uri, {Encoding encoding}) =>
48 io.readAsString(uri, encoding);
49 }
50
51 // A loader that implements base.PackageLoader *and* ResourceLoader from this
52 // file.
53 class PackageLoader extends base.PackageLoader implements ResourceLoader {
54 const PackageLoader(ResourceLoader loader) : super(loader);
55 }
OLDNEW
« no previous file with comments | « lib/src/io/io.dart ('k') | lib/src/io/resource.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698