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

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 1651023003: Fix EOF detection when reading an entire file (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 // Read the file in blocks of size 64k. 7 // Read the file in blocks of size 64k.
8 const int _BLOCK_SIZE = 64 * 1024; 8 const int _BLOCK_SIZE = 64 * 1024;
9 9
10 10
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 var consumer = new _FileStreamConsumer(this, mode); 439 var consumer = new _FileStreamConsumer(this, mode);
440 return new IOSink(consumer, encoding: encoding); 440 return new IOSink(consumer, encoding: encoding);
441 } 441 }
442 442
443 Future<List<int>> readAsBytes() { 443 Future<List<int>> readAsBytes() {
444 Future<List<int>> readDataChunked(file) { 444 Future<List<int>> readDataChunked(file) {
445 var builder = new BytesBuilder(copy: false); 445 var builder = new BytesBuilder(copy: false);
446 var completer = new Completer(); 446 var completer = new Completer();
447 void read() { 447 void read() {
448 file.read(_BLOCK_SIZE).then((data) { 448 file.read(_BLOCK_SIZE).then((data) {
449 if (data.length > 0) builder.add(data); 449 if (data.length > 0) {
450 if (data.length == _BLOCK_SIZE) { 450 builder.add(data);
451 read(); 451 read();
452 } else { 452 } else {
453 completer.complete(builder.takeBytes()); 453 completer.complete(builder.takeBytes());
454 } 454 }
455 }, onError: completer.completeError); 455 }, onError: completer.completeError);
456 } 456 }
457 read(); 457 read();
458 return completer.future; 458 return completer.future;
459 } 459 }
460 460
(...skipping 12 matching lines...) Expand all
473 var opened = openSync(); 473 var opened = openSync();
474 try { 474 try {
475 var data; 475 var data;
476 var length = opened.lengthSync(); 476 var length = opened.lengthSync();
477 if (length == 0) { 477 if (length == 0) {
478 // May be character device, try to read it in chunks. 478 // May be character device, try to read it in chunks.
479 var builder = new BytesBuilder(copy: false); 479 var builder = new BytesBuilder(copy: false);
480 do { 480 do {
481 data = opened.readSync(_BLOCK_SIZE); 481 data = opened.readSync(_BLOCK_SIZE);
482 if (data.length > 0) builder.add(data); 482 if (data.length > 0) builder.add(data);
483 } while (data.length == _BLOCK_SIZE); 483 } while (data.length > 0);
484 data = builder.takeBytes(); 484 data = builder.takeBytes();
485 } else { 485 } else {
486 data = opened.readSync(length); 486 data = opened.readSync(length);
487 } 487 }
488 return data; 488 return data;
489 } finally { 489 } finally {
490 opened.closeSync(); 490 opened.closeSync();
491 } 491 }
492 } 492 }
493 493
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 void _checkAvailable() { 1019 void _checkAvailable() {
1020 if (_asyncDispatched) { 1020 if (_asyncDispatched) {
1021 throw new FileSystemException("An async operation is currently pending", 1021 throw new FileSystemException("An async operation is currently pending",
1022 path); 1022 path);
1023 } 1023 }
1024 if (closed) { 1024 if (closed) {
1025 throw new FileSystemException("File closed", path); 1025 throw new FileSystemException("File closed", path);
1026 } 1026 }
1027 } 1027 }
1028 } 1028 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698