| OLD | NEW |
| 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 List<int> bytes = readAsBytesSync(); | 514 List<int> bytes = readAsBytesSync(); |
| 515 return _decodeString(bytes, encoding); | 515 return _decodeString(bytes, encoding); |
| 516 } | 516 } |
| 517 | 517 |
| 518 static List<String> _decodeLines(List<int> bytes, Encoding encoding) { | 518 static List<String> _decodeLines(List<int> bytes, Encoding encoding) { |
| 519 if (bytes.length == 0) return []; | 519 if (bytes.length == 0) return []; |
| 520 var list = []; | 520 var list = []; |
| 521 var controller = new StreamController(sync: true); | 521 var controller = new StreamController(sync: true); |
| 522 controller.stream | 522 controller.stream |
| 523 .transform(new StringDecoder(encoding)) | 523 .transform(new StringDecoder(encoding)) |
| 524 .transform(new LineTransformer()) | 524 .transform(new LineSplitter()) |
| 525 .listen((line) => list.add(line)); | 525 .listen((line) => list.add(line)); |
| 526 controller.add(bytes); | 526 controller.add(bytes); |
| 527 controller.close(); | 527 controller.close(); |
| 528 return list; | 528 return list; |
| 529 } | 529 } |
| 530 | 530 |
| 531 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}) { | 531 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}) { |
| 532 _ensureFileService(); | 532 _ensureFileService(); |
| 533 return readAsBytes().then((bytes) { | 533 return readAsBytes().then((bytes) { |
| 534 return _decodeLines(bytes, encoding); | 534 return _decodeLines(bytes, encoding); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 977 void _checkNotClosed() { | 977 void _checkNotClosed() { |
| 978 if (closed) { | 978 if (closed) { |
| 979 throw new FileException("File closed", path); | 979 throw new FileException("File closed", path); |
| 980 } | 980 } |
| 981 } | 981 } |
| 982 | 982 |
| 983 Future _closedException() { | 983 Future _closedException() { |
| 984 return new Future.error(new FileException("File closed", path)); | 984 return new Future.error(new FileException("File closed", path)); |
| 985 } | 985 } |
| 986 } | 986 } |
| OLD | NEW |