22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // TODO: Consider making this a stand-alone package, if useful.
6-
75/// Make it possible to load resources, independent of how the Dart app is run.
86///
97/// Future<String> getTemplateFile(String templatePath) {
@@ -14,7 +12,7 @@ library dartdoc.resource_loader;
1412
1513import 'dart:async' show Future;
1614import 'dart:io' show Platform, File, Directory;
17- import 'dart:typed_data' ;
15+ import 'dart:typed_data' show Uint8List ;
1816
1917import 'package:http/http.dart' as http;
2018import 'package:path/path.dart' as p;
@@ -24,20 +22,27 @@ import 'package:pub_cache/pub_cache.dart';
2422String packageRootPath;
2523
2624/// Loads a `package:` resource as a String.
27- Future <String > loadAsString (String path) async {
25+ Future <String > loadAsString (String path) {
2826 if (! path.startsWith ('package:' )) {
2927 throw new ArgumentError ('path must begin with package:' );
3028 }
31- Uint8List bytes = await _doLoad (path);
32- return new String .fromCharCodes (bytes);
29+ return new Resource (path).readAsString ().catchError ((_) async {
30+ // TODO: Remove once https://github.com/dart-lang/pub/issues/22 is fixed.
31+ var bytes = await _doLoad (path);
32+ return new String .fromCharCodes (bytes);
33+ });
3334}
3435
35- /// Loads a `package:` resource as an [Uint8List ] .
36- Future <Uint8List > loadAsBytes (String path) {
36+ /// Loads a `package:` resource as an [List<int> ] .
37+ Future <List < int > > loadAsBytes (String path) {
3738 if (! path.startsWith ('package:' )) {
3839 throw new ArgumentError ('path must begin with package:' );
3940 }
40- return _doLoad (path);
41+
42+ return new Resource (path).readAsBytes ().catchError ((_) {
43+ // TODO: Remove once https://github.com/dart-lang/pub/issues/22 is fixed.
44+ return _doLoad (path);
45+ });
4146}
4247
4348/// Determine how to do the load. HTTP? Snapshotted? From source?
0 commit comments