| OLD | NEW |
| 1 // Copyright (c) 2012, 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 | 7 |
| 8 class _FileStream extends Stream<List<int>> { | 8 class _FileStream extends Stream<List<int>> { |
| 9 // Stream controller. | 9 // Stream controller. |
| 10 StreamController<List<int>> _controller; | 10 StreamController<List<int>> _controller; |
| 11 | 11 |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 String readAsStringSync([Encoding encoding = Encoding.UTF_8]) { | 518 String readAsStringSync([Encoding encoding = Encoding.UTF_8]) { |
| 519 List<int> bytes = readAsBytesSync(); | 519 List<int> bytes = readAsBytesSync(); |
| 520 return _decodeString(bytes, encoding); | 520 return _decodeString(bytes, encoding); |
| 521 } | 521 } |
| 522 | 522 |
| 523 static List<String> _decodeLines(List<int> bytes, Encoding encoding) { | 523 static List<String> _decodeLines(List<int> bytes, Encoding encoding) { |
| 524 if (bytes.length == 0) return []; | 524 if (bytes.length == 0) return []; |
| 525 var list = []; | 525 var list = []; |
| 526 var controller = new StreamController(); | 526 var controller = new StreamController(); |
| 527 controller.stream | 527 controller.stream |
| 528 .transform(new StringDecoder(encoding)) | 528 .transform(new StringDecoder(encoding)) |
| 529 .transform(new LineTransformer()) | 529 .transform(new LineTransformer()) |
| 530 .listen((line) => list.add(line)); | 530 .listen((line) => list.add(line)); |
| 531 controller.add(bytes); | 531 controller.add(bytes); |
| 532 controller.close(); | 532 controller.close(); |
| 533 return list; | 533 return list; |
| 534 } | 534 } |
| 535 | 535 |
| 536 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]) { | 536 Future<List<String>> readAsLines([Encoding encoding = Encoding.UTF_8]) { |
| 537 _ensureFileService(); | 537 _ensureFileService(); |
| 538 Completer<List<String>> completer = new Completer<List<String>>(); | 538 Completer<List<String>> completer = new Completer<List<String>>(); |
| 539 return readAsBytes().then((bytes) { | 539 return readAsBytes().then((bytes) { |
| 540 return _decodeLines(bytes, encoding); | 540 return _decodeLines(bytes, encoding); |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 new FileIOException("File closed '$_name'")); | 1049 new FileIOException("File closed '$_name'")); |
| 1050 }); | 1050 }); |
| 1051 return completer.future; | 1051 return completer.future; |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 final String _name; | 1054 final String _name; |
| 1055 int _id; | 1055 int _id; |
| 1056 | 1056 |
| 1057 SendPort _fileService; | 1057 SendPort _fileService; |
| 1058 } | 1058 } |
| OLD | NEW |