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

Unified Diff: sdk/lib/io/file_impl.dart

Issue 13453002: Read files in chunks, not relaying on size. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 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
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index f6fdb84e1a55f41d09529815d42c9477224d96c7..8ab05f6c5730b2b22159d85da821d1e590107d1a 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -4,14 +4,14 @@
part of dart.io;
+// Read the file in blocks of size 64k.
+const int _BLOCK_SIZE = 64 * 1024;
+
class _FileStream extends Stream<List<int>> {
// Stream controller.
StreamController<List<int>> _controller;
- // Read the file in blocks of size 64k.
- final int _blockSize = 64 * 1024;
-
// Information about the underlying file.
String _path;
RandomAccessFile _openedFile;
@@ -76,7 +76,7 @@ class _FileStream extends Stream<List<int>> {
}
return null;
} else {
- return _openedFile.read(_blockSize);
+ return _openedFile.read(_BLOCK_SIZE);
}
})
.then((block) {
@@ -503,14 +503,13 @@ class _File extends _FileBase implements File {
List<int> readAsBytesSync() {
var opened = openSync();
- var length = opened.lengthSync();
- var result = new Uint8List(length);
- var read = opened.readListSync(result, 0, length);
- if (read != length) {
- throw new FileIOException("Failed to read file");
+ var chunks = new _BufferList();
+ var data;
+ while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) {
+ chunks.add(data);
}
opened.closeSync();
- return result;
+ return chunks.readBytes();
}
Future<String> readAsString({Encoding encoding: Encoding.UTF_8}) {

Powered by Google App Engine
This is Rietveld 408576698