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

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: Fix merge issue Created 7 years, 1 month 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 | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/file_impl.dart
diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
index e7080d73ff14ef8242361da56f3f5f43fedc3ce7..8a7ce392de92689007e6dd043b68900fc2961756 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -494,28 +494,37 @@ class _File extends FileSystemEntity 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: UTF8}) {
+ Encoding encoding: UTF8,
+ bool flush: false}) {
try {
- return writeAsBytes(encoding.encode(contents), mode: mode);
+ return writeAsBytes(encoding.encode(contents), mode: mode, flush: flush);
} catch (e) {
return new Future.error(e);
}
@@ -523,8 +532,9 @@ class _File extends FileSystemEntity implements File {
void writeAsStringSync(String contents,
{FileMode mode: FileMode.WRITE,
- Encoding encoding: UTF8}) {
- writeAsBytesSync(encoding.encode(contents), mode: mode);
+ Encoding encoding: UTF8,
+ bool flush: false}) {
+ writeAsBytesSync(encoding.encode(contents), mode: mode, flush: flush);
}
String toString() => "File: '$path'";
« no previous file with comments | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698