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

Unified Diff: sdk/lib/io/file_impl.dart

Issue 20745006: Add a flush operations to IOSink (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index 078999024b75f798800ff7b1ef9b981865a35879..a970163b1c66b6657325dffccad2242dbf811e62 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -196,6 +196,12 @@ class _FileStreamConsumer extends StreamConsumer<List<int>> {
Future<File> close() {
return _openFuture.then((openedFile) => openedFile.close());
}
+
+ Future flush() {
+ return _openFuture
+ .then((openedFile) => openedFile.flush())
+ .then((randomAccessfile) => new Future.value(null));
+ }
}
@@ -540,28 +546,38 @@ class _File implements File {
}
Future<File> writeAsBytes(List<int> bytes,
- {FileMode mode: FileMode.WRITE}) {
+ {FileMode mode: FileMode.WRITE,
+ bool flush: false}) {
try {
IOSink sink = openWrite(mode: mode);
sink.add(bytes);
- sink.close();
+ if (flush) {
+ sink.flush().then((_) => sink.close());
+ } else {
+ sink.close();
+ }
return sink.done.then((_) => this);
} catch (e) {
return new Future.error(e);
}
}
- void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}) {
+ void writeAsBytesSync(List<int> bytes,
+ {FileMode mode: FileMode.WRITE,
+ bool flush: false}) {
RandomAccessFile opened = openSync(mode: mode);
opened.writeFromSync(bytes, 0, bytes.length);
+ if (flush) opened.flushSync();
opened.closeSync();
}
Future<File> writeAsString(String contents,
{FileMode mode: FileMode.WRITE,
- Encoding encoding: Encoding.UTF_8}) {
+ Encoding encoding: Encoding.UTF_8,
+ bool flush: false}) {
try {
- return writeAsBytes(_encodeString(contents, encoding), mode: mode);
+ return writeAsBytes(
+ _encodeString(contents, encoding), mode: mode, flush: flush);
} catch (e) {
return new Future.error(e);
}
@@ -569,8 +585,10 @@ class _File implements File {
void writeAsStringSync(String contents,
{FileMode mode: FileMode.WRITE,
- Encoding encoding: Encoding.UTF_8}) {
- writeAsBytesSync(_encodeString(contents, encoding), mode: mode);
+ Encoding encoding: Encoding.UTF_8,
+ bool flush: false}) {
+ writeAsBytesSync(
+ _encodeString(contents, encoding), mode: mode, flush: flush);
}
String get path => _path;
« no previous file with comments | « sdk/lib/io/file.dart ('k') | sdk/lib/io/io_sink.dart » ('j') | sdk/lib/io/io_sink.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698