| 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 20 matching lines...) Expand all Loading... |
| 31 _setupController(); | 31 _setupController(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 _FileStream.forStdin() : _position = 0 { | 34 _FileStream.forStdin() : _position = 0 { |
| 35 _setupController(); | 35 _setupController(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 StreamSubscription<List<int>> listen(void onData(List<int> event), | 38 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 39 {void onError(AsyncError error), | 39 {void onError(AsyncError error), |
| 40 void onDone(), | 40 void onDone(), |
| 41 bool unsubscribeOnError}) { | 41 bool cancelOnError}) { |
| 42 return _controller.stream.listen(onData, | 42 return _controller.stream.listen(onData, |
| 43 onError: onError, | 43 onError: onError, |
| 44 onDone: onDone, | 44 onDone: onDone, |
| 45 unsubscribeOnError: unsubscribeOnError); | 45 cancelOnError: cancelOnError); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void _setupController() { | 48 void _setupController() { |
| 49 _controller = new StreamController<List<int>>( | 49 _controller = new StreamController<List<int>>( |
| 50 onSubscriptionStateChange: _onSubscriptionStateChange, | 50 onSubscriptionStateChange: _onSubscriptionStateChange, |
| 51 onPauseStateChange: _onPauseStateChange); | 51 onPauseStateChange: _onPauseStateChange); |
| 52 } | 52 } |
| 53 | 53 |
| 54 Future _closeFile() { | 54 Future _closeFile() { |
| 55 Future closeFuture; | 55 Future closeFuture; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 completer.completeError(e); | 175 completer.completeError(e); |
| 176 }); | 176 }); |
| 177 }, | 177 }, |
| 178 onDone: () { | 178 onDone: () { |
| 179 completer.complete(_file); | 179 completer.complete(_file); |
| 180 }, | 180 }, |
| 181 onError: (e) { | 181 onError: (e) { |
| 182 openedFile.close(); | 182 openedFile.close(); |
| 183 completer.completeError(e); | 183 completer.completeError(e); |
| 184 }, | 184 }, |
| 185 unsubscribeOnError: true); | 185 cancelOnError: true); |
| 186 }) | 186 }) |
| 187 .catchError((e) { | 187 .catchError((e) { |
| 188 completer.completeError(e); | 188 completer.completeError(e); |
| 189 }); | 189 }); |
| 190 return completer.future; | 190 return completer.future; |
| 191 } | 191 } |
| 192 | 192 |
| 193 Future<File> close() { | 193 Future<File> close() { |
| 194 return _openFuture.then((openedFile) => openedFile.close()); | 194 return _openFuture.then((openedFile) => openedFile.close()); |
| 195 } | 195 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 openRead().listen( | 490 openRead().listen( |
| 491 (d) => chunks.add(d), | 491 (d) => chunks.add(d), |
| 492 onDone: () { | 492 onDone: () { |
| 493 var result = chunks.readBytes(chunks.length); | 493 var result = chunks.readBytes(chunks.length); |
| 494 if (result == null) result = <int>[]; | 494 if (result == null) result = <int>[]; |
| 495 completer.complete(result); | 495 completer.complete(result); |
| 496 }, | 496 }, |
| 497 onError: (e) { | 497 onError: (e) { |
| 498 completer.completeError(e); | 498 completer.completeError(e); |
| 499 }, | 499 }, |
| 500 unsubscribeOnError: true); | 500 cancelOnError: true); |
| 501 return completer.future; | 501 return completer.future; |
| 502 } | 502 } |
| 503 | 503 |
| 504 List<int> readAsBytesSync() { | 504 List<int> readAsBytesSync() { |
| 505 var opened = openSync(); | 505 var opened = openSync(); |
| 506 var chunks = new _BufferList(); | 506 var chunks = new _BufferList(); |
| 507 var data; | 507 var data; |
| 508 while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) { | 508 while ((data = opened.readSync(_BLOCK_SIZE)).length > 0) { |
| 509 chunks.add(data); | 509 chunks.add(data); |
| 510 } | 510 } |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 new FileIOException("File closed '$_path'")); | 1052 new FileIOException("File closed '$_path'")); |
| 1053 }); | 1053 }); |
| 1054 return completer.future; | 1054 return completer.future; |
| 1055 } | 1055 } |
| 1056 | 1056 |
| 1057 final String _path; | 1057 final String _path; |
| 1058 int _id; | 1058 int _id; |
| 1059 | 1059 |
| 1060 SendPort _fileService; | 1060 SendPort _fileService; |
| 1061 } | 1061 } |
| OLD | NEW |