| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (!_unsubscribed) { | 88 if (!_unsubscribed) { |
| 89 _controller.addError(new RangeError("Bad end position: $_end")); | 89 _controller.addError(new RangeError("Bad end position: $_end")); |
| 90 _closeFile(); | 90 _closeFile(); |
| 91 _unsubscribed = true; | 91 _unsubscribed = true; |
| 92 } | 92 } |
| 93 return; | 93 return; |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 _openedFile.read(readBytes) | 96 _openedFile.read(readBytes) |
| 97 .then((block) { | 97 .then((block) { |
| 98 _readInProgress = false; |
| 98 if (_unsubscribed) { | 99 if (_unsubscribed) { |
| 99 _closeFile(); | 100 _closeFile(); |
| 100 return; | 101 return; |
| 101 } | 102 } |
| 102 _readInProgress = false; | |
| 103 _position += block.length; | 103 _position += block.length; |
| 104 if (block.length < readBytes || | 104 if (block.length < readBytes || |
| 105 (_end != null && _position == _end)) { | 105 (_end != null && _position == _end)) { |
| 106 _atEnd = true; | 106 _atEnd = true; |
| 107 } | 107 } |
| 108 if (!_atEnd && !_controller.isPaused) { |
| 109 _readBlock(); |
| 110 } |
| 108 _controller.add(block); | 111 _controller.add(block); |
| 109 if (!_controller.isPaused) { | 112 if (_atEnd) { |
| 110 _readBlock(); | 113 _closeFile(); |
| 111 } | 114 } |
| 112 }) | 115 }) |
| 113 .catchError((e, s) { | 116 .catchError((e, s) { |
| 114 if (!_unsubscribed) { | 117 if (!_unsubscribed) { |
| 115 _controller.addError(e, s); | 118 _controller.addError(e, s); |
| 116 _closeFile(); | 119 _closeFile(); |
| 117 _unsubscribed = true; | 120 _unsubscribed = true; |
| 118 } | 121 } |
| 119 }); | 122 }); |
| 120 } | 123 } |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 void _checkAvailable() { | 915 void _checkAvailable() { |
| 913 if (_asyncDispatched) { | 916 if (_asyncDispatched) { |
| 914 throw new FileSystemException("An async operation is currently pending", | 917 throw new FileSystemException("An async operation is currently pending", |
| 915 path); | 918 path); |
| 916 } | 919 } |
| 917 if (closed) { | 920 if (closed) { |
| 918 throw new FileSystemException("File closed", path); | 921 throw new FileSystemException("File closed", path); |
| 919 } | 922 } |
| 920 } | 923 } |
| 921 } | 924 } |
| OLD | NEW |