Index: sdk/lib/_internal/compiler/implementation/source_file_provider.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/source_file_provider.dart b/sdk/lib/_internal/compiler/implementation/source_file_provider.dart |
index 352f03cea24d463cddb793d777128818c793c94c..aaad3ea318cf8760139e4114aa1532b322b2f3be 100644 |
--- a/sdk/lib/_internal/compiler/implementation/source_file_provider.dart |
+++ b/sdk/lib/_internal/compiler/implementation/source_file_provider.dart |
@@ -14,14 +14,16 @@ import 'colors.dart' as colors; |
import 'source_file.dart'; |
import 'filenames.dart'; |
import 'util/uri_extras.dart'; |
+import 'dart:typed_data'; |
-String readAll(String filename) { |
+List<int> readAll(String filename) { |
var file = (new File(filename)).openSync(); |
var length = file.lengthSync(); |
- var buffer = new List<int>(length); |
+ // +1 to have a 0 terminated list, see [Scanner]. |
+ var buffer = new Uint8List(length + 1); |
var bytes = file.readIntoSync(buffer, 0, length); |
file.closeSync(); |
- return UTF8.decode(buffer); |
+ return buffer; |
} |
class SourceFileProvider { |
@@ -31,10 +33,14 @@ class SourceFileProvider { |
int dartCharactersRead = 0; |
Future<String> readStringFromUri(Uri resourceUri) { |
+ return readFromUri(resourceUri).then(UTF8.decode); |
+ } |
+ |
+ Future<List<int>> readFromUri(Uri resourceUri) { |
if (resourceUri.scheme != 'file') { |
throw new ArgumentError("Unknown scheme in uri '$resourceUri'"); |
} |
- String source; |
+ List<int> source; |
try { |
source = readAll(uriPathToNative(resourceUri.path)); |
} on FileException catch (ex) { |
@@ -43,12 +49,12 @@ class SourceFileProvider { |
"(${ex.osError})"); |
} |
dartCharactersRead += source.length; |
- sourceFiles[resourceUri.toString()] = new SourceFile( |
+ sourceFiles[resourceUri.toString()] = new Utf8BytesSourceFile( |
relativize(cwd, resourceUri, isWindows), source); |
return new Future.value(source); |
} |
- Future<String> call(Uri resourceUri) => readStringFromUri(resourceUri); |
+ Future<List<int>> call(Uri resourceUri) => readFromUri(resourceUri); |
} |
class FormattingDiagnosticHandler { |