| Index: sdk/lib/io/file_impl.dart
|
| diff --git a/sdk/lib/io/file_impl.dart b/sdk/lib/io/file_impl.dart
|
| index 71dca70cef7204961ecce61f26c8437a4542c4f9..e6acc5abd88c76f48fcfeb994693ad332f13fa0e 100644
|
| --- a/sdk/lib/io/file_impl.dart
|
| +++ b/sdk/lib/io/file_impl.dart
|
| @@ -206,6 +206,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));
|
| + }
|
| }
|
|
|
|
|
| @@ -482,26 +488,35 @@ 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);
|
| } catch (e) {
|
| @@ -511,7 +526,8 @@ class _File extends FileSystemEntity implements File {
|
|
|
| void writeAsStringSync(String contents,
|
| {FileMode mode: FileMode.WRITE,
|
| - Encoding encoding: UTF8}) {
|
| + Encoding encoding: UTF8,
|
| + bool flush: false}) {
|
| writeAsBytesSync(encoding.encode(contents), mode: mode);
|
| }
|
|
|
|
|