| 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}) {
|
|
|