| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 class _FileInputStream extends _BaseDataInputStream implements InputStream { | 7 class _FileInputStream extends _BaseDataInputStream implements InputStream { |
| 8 _FileInputStream(String name) | 8 _FileInputStream(String name) |
| 9 : _data = const [], | 9 : _data = const [], |
| 10 _position = 0, | 10 _position = 0, |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 } | 569 } |
| 570 | 570 |
| 571 Stream<List<int>> openForRead() { | 571 Stream<List<int>> openForRead() { |
| 572 return new _InputStreamController(new _FileInputStream(_name)).stream; | 572 return new _InputStreamController(new _FileInputStream(_name)).stream; |
| 573 } | 573 } |
| 574 | 574 |
| 575 Future<StreamSink<List<int>>> openForWrite([FileMode mode = FileMode.WRITE]) { | 575 Future<StreamSink<List<int>>> openForWrite([FileMode mode = FileMode.WRITE]) { |
| 576 return open(mode).then((file) { | 576 return open(mode).then((file) { |
| 577 var controller = new StreamController(); | 577 var controller = new StreamController(); |
| 578 | 578 |
| 579 var subscription = controller.subscribe(); | 579 var subscription = controller.listen( |
| 580 subscription.onData((data) { | 580 (data) { |
| 581 // TODO(ajohnsen): handle errors correctly. | 581 // TODO(ajohnsen): handle errors correctly. |
| 582 file.writeList(data, 0, data.length); | 582 file.writeList(data, 0, data.length); |
| 583 }); | 583 }, |
| 584 subscription.onDone(file.close); | 584 onDone: file.close); |
| 585 | 585 |
| 586 return controller.sink; | 586 return controller.sink; |
| 587 }); | 587 }); |
| 588 } | 588 } |
| 589 | 589 |
| 590 Future<List<int>> readAsBytes() { | 590 Future<List<int>> readAsBytes() { |
| 591 _ensureFileService(); | 591 _ensureFileService(); |
| 592 Completer<List<int>> completer = new Completer<List<int>>(); | 592 Completer<List<int>> completer = new Completer<List<int>>(); |
| 593 var chunks = new _BufferList(); | 593 var chunks = new _BufferList(); |
| 594 var stream = openInputStream(); | 594 var stream = openInputStream(); |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 new FileIOException("File closed '$_name'")); | 1173 new FileIOException("File closed '$_name'")); |
| 1174 }); | 1174 }); |
| 1175 return completer.future; | 1175 return completer.future; |
| 1176 } | 1176 } |
| 1177 | 1177 |
| 1178 final String _name; | 1178 final String _name; |
| 1179 int _id; | 1179 int _id; |
| 1180 | 1180 |
| 1181 SendPort _fileService; | 1181 SendPort _fileService; |
| 1182 } | 1182 } |
| OLD | NEW |