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

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

Issue 1387163002: Add Resource package. (Closed) Base URL: https://github.com/dart-lang/resource.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
(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 library resource.loader;
6
7 import "dart:async" show Future, Stream;
8 import "dart:convert" show Encoding;
9 import "io.dart" as io; // TODO: make this import configuration dependent.
10
11 /// Resource loading strategy.
12 ///
13 /// An abstraction of the functionality needed to load resources.
14 ///
15 /// An implementation decides which URI schemes it supports.
16 abstract class ResourceLoader {
17 /// Reads the file located by [uri] as a stream of bytes.
floitsch 2015/10/13 12:47:50 I wouldn't use the term "file".
18 Stream<List<int>> openRead(Uri uri);
19
20 /// Reads the file located by [uri] as a list of bytes.
21 Future<List<int>> readAsBytes(Uri uri);
22
23 /// Reads the file located by [uri] as a [String].
24 ///
25 /// The file bytes are decoded using [encoding].
26 /// If [encoding] is omittted, it defaults to UTF-8.
floitsch 2015/10/13 12:47:50 omitted
27 Future<String> readAsString(Uri uri, { Encoding encoding });
28 }
29
30 /// Default implementation of [ResourceLoader].
31 ///
32 /// Uses the system's available loading functionality to implement the
33 /// loading functions.
34 class DefaultLoader implements ResourceLoader {
35 const DefaultLoader();
36
37 Stream<List<int>> openRead(Uri uri) => io.readAsStream(uri);
38
39 Future<List<int>> readAsBytes(Uri uri) => io.readAsBytes(uri);
40
41 Future<String> readAsString(Uri uri, { Encoding encoding }) =>
42 io.readAsString(uri, encoding);
43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698