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

Unified Diff: runtime/bin/file_impl.dart

Issue 9969202: Add method flush to output stream (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased to r8419 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 | runtime/bin/http_impl.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 48ae70a51d4d175ee2158181c30a7fbb7ad1cdbb..d18552275210a156a983021c213e65860a86b44c 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -129,9 +129,17 @@ class _FileInputStream extends _BaseDataInputStream implements InputStream {
}
+class _PendingOperation {
+ const _PendingOperation(this._id);
+ static final _PendingOperation CLOSE = const _PendingOperation(0);
+ static final _PendingOperation FLUSH = const _PendingOperation(1);
+ final int _id;
+}
+
+
class _FileOutputStream extends _BaseOutputStream implements OutputStream {
_FileOutputStream(String name, FileMode mode) {
- _pendingOperations = new List<List<int>>();
+ _pendingOperations = new List();
var f = new File(name);
var openFuture = f.open(mode);
openFuture.then((openedFile) {
@@ -176,9 +184,19 @@ class _FileOutputStream extends _BaseOutputStream implements OutputStream {
return write(copy);
}
+
+ void flush() {
+ if (_file == null) {
+ _pendingOperations.add(_PendingOperation.FLUSH);
+ } else {
+ _file.flush().then((ignored) => null);
+ }
+ }
+
+
void close() {
if (_file == null) {
- _pendingOperations.add(null);
+ _pendingOperations.add(_PendingOperation.CLOSE);
} else if (!_streamMarkedClosed) {
_file.close().then((ignore) {
if (_onClosed != null) _onClosed();
@@ -207,7 +225,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;
}
@@ -245,7 +272,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;
« no previous file with comments | « no previous file | runtime/bin/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698