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

Unified Diff: runtime/bin/file_impl.dart

Issue 10913005: Better handling of reading empty files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed the aproach slightly Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/tests/vm/data/empty_file » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 2d2e6d0d27d059817e59da7e10d44afc7bc5c10b..eafb4bd2492459ea8193d11adbd0ac13402df0b3 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -692,7 +692,9 @@ class _File extends _FileBase implements File {
var chunks = new _BufferList();
var stream = openInputStream();
stream.onClosed = () {
- completer.complete(chunks.readBytes(chunks.length));
+ var result = chunks.readBytes(chunks.length);
+ if (result == null) result = <int>[];
+ completer.complete(result);
};
stream.onData = () {
var chunk = stream.read();
@@ -717,6 +719,7 @@ class _File extends _FileBase implements File {
Future<String> readAsText([Encoding encoding = Encoding.UTF_8]) {
_ensureFileService();
return readAsBytes().transform((bytes) {
+ if (bytes.length == 0) return "";
var decoder = _StringDecoders.decoder(encoding);
decoder.write(bytes);
return decoder.decoded;
@@ -726,6 +729,7 @@ class _File extends _FileBase implements File {
String readAsTextSync([Encoding encoding = Encoding.UTF_8]) {
var decoder = _StringDecoders.decoder(encoding);
List<int> bytes = readAsBytesSync();
+ if (bytes.length == 0) return "";
decoder.write(bytes);
return decoder.decoded;
}
« no previous file with comments | « no previous file | runtime/tests/vm/data/empty_file » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698