Index: runtime/bin/file_impl.dart |
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart |
index 66fb6bdfa11844e12399d43bff46378ca9cc4260..26928519349a88bcd216539958624396e366273a 100644 |
--- a/runtime/bin/file_impl.dart |
+++ b/runtime/bin/file_impl.dart |
@@ -91,9 +91,16 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream { |
} |
+class _PendingOperation { |
+ const _PendingOperation(); |
+ static final _PendingOperation CLOSE = const _PendingOperation(); |
+ static final _PendingOperation FLUSH = const _PendingOperation(); |
+} |
+ |
+ |
class _FileOutputStream extends _BaseOutputStream implements OutputStream { |
_FileOutputStream(String name, FileMode mode) { |
- _pendingOperations = new List<List<int>>(); |
+ _pendingOperations = new List(); |
var f = new File(name); |
f.open(mode, (openedFile) { |
_file = openedFile; |
@@ -150,9 +157,17 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream { |
return write(copy); |
} |
+ void flush() { |
+ if (_file == null) { |
+ _pendingOperations.add(_PendingOperation.FLUSH); |
+ } else { |
+ _file.flush(); |
Mads Ager (google)
2012/04/17 11:56:44
Isn't _file a RandomAccessFile? Doesn't flush take
Søren Gjesse
2012/04/17 13:14:19
It does - not sure why no tests failed.
Turend ou
|
+ } |
+ } |
+ |
void close() { |
if (_file == null) { |
- _pendingOperations.add(null); |
+ _pendingOperations.add(_PendingOperation.CLOSE); |
} else if (!_streamMarkedClosed) { |
_file.close(() { |
if (_onClosed != null) _onClosed(); |
@@ -175,7 +190,16 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream { |
void _processPendingOperations() { |
_pendingOperations.forEach((buffer) { |
- (buffer != null) ? write(buffer) : close(); |
+ if (buffer is _PendingOperation) { |
+ if (buffer === _PendingOperation.CLOSE) { |
+ close(); |
+ } else { |
+ assert(buffer === _PendingOperation.FLUSH); |
+ flush(); |
+ } |
+ } else { |
+ write(buffer); |
+ } |
}); |
_pendingOperations = null; |
} |
@@ -196,7 +220,7 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream { |
// List of pending writes that were issued before the underlying |
// file was successfully opened. |
- List<List<int>> _pendingOperations; |
+ List _pendingOperations; |
Function _onNoPendingWrites; |
Function _onClosed; |