Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: runtime/bin/file_impl.dart

Issue 10546051: Change FileInputStream to only call onClosed callback when underlying file has been closed. Change… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 0706fbe468a31b7e6c82977d52af36364a7f3737..48ae70a51d4d175ee2158181c30a7fbb7ad1cdbb 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -37,13 +37,21 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
chained.then((ignored) => _checkScheduleCallbacks());
}
+ void _closeFile() {
+ if (!_openedFile.closed) {
+ _openedFile.close().then((ignore) {
+ _streamMarkedClosed = true;
+ _checkScheduleCallbacks();
+ });
+ }
+ }
+
Future<int> _fillBuffer() {
Expect.equals(_position, _data.length);
int size = Math.min(_bufferLength, _fileLength - _filePosition);
if (size == 0) {
- _streamMarkedClosed = true;
- _openedFile.close();
+ _closeFile();
return new Future.immediate(0);
}
if (_data.length != size) {
@@ -58,8 +66,7 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
_position = 0;
if (_fileLength == _filePosition) {
- _streamMarkedClosed = true;
- _openedFile.close();
+ _closeFile();
}
return read;
});
@@ -106,12 +113,10 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
}
void _close() {
- _streamMarkedClosed = true;
_data = [];
_position = 0;
- if (!_openedFile.closed) {
- _openedFile.close();
- }
+ _filePosition = _fileLength;
+ _closeFile();
}
static final int _bufferLength = 64 * 1024;
« no previous file with comments | « no previous file | tests/standalone/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698