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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/io/file.dart ('k') | tests/standalone/io/file_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 // Read the file in blocks of size 64k. 7 // Read the file in blocks of size 64k.
8 const int _BLOCK_SIZE = 64 * 1024; 8 const int _BLOCK_SIZE = 64 * 1024;
9 9
10 10
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 return readAsBytes().then((bytes) { 487 return readAsBytes().then((bytes) {
488 return _decodeLines(bytes, encoding); 488 return _decodeLines(bytes, encoding);
489 }); 489 });
490 } 490 }
491 491
492 List<String> readAsLinesSync({Encoding encoding: UTF8}) { 492 List<String> readAsLinesSync({Encoding encoding: UTF8}) {
493 return _decodeLines(readAsBytesSync(), encoding); 493 return _decodeLines(readAsBytesSync(), encoding);
494 } 494 }
495 495
496 Future<File> writeAsBytes(List<int> bytes, 496 Future<File> writeAsBytes(List<int> bytes,
497 {FileMode mode: FileMode.WRITE}) { 497 {FileMode mode: FileMode.WRITE,
498 bool flush: false}) {
498 try { 499 try {
499 IOSink sink = openWrite(mode: mode); 500 IOSink sink = openWrite(mode: mode);
500 sink.add(bytes); 501 sink.add(bytes);
501 sink.close(); 502 if (flush) {
503 sink.flush().then((_) => sink.close());
504 } else {
505 sink.close();
506 }
502 return sink.done.then((_) => this); 507 return sink.done.then((_) => this);
503 } catch (e) { 508 } catch (e) {
504 return new Future.error(e); 509 return new Future.error(e);
505 } 510 }
506 } 511 }
507 512
508 void writeAsBytesSync(List<int> bytes, {FileMode mode: FileMode.WRITE}) { 513 void writeAsBytesSync(List<int> bytes,
514 {FileMode mode: FileMode.WRITE,
515 bool flush: false}) {
509 RandomAccessFile opened = openSync(mode: mode); 516 RandomAccessFile opened = openSync(mode: mode);
510 opened.writeFromSync(bytes, 0, bytes.length); 517 opened.writeFromSync(bytes, 0, bytes.length);
518 if (flush) opened.flushSync();
511 opened.closeSync(); 519 opened.closeSync();
512 } 520 }
513 521
514 Future<File> writeAsString(String contents, 522 Future<File> writeAsString(String contents,
515 {FileMode mode: FileMode.WRITE, 523 {FileMode mode: FileMode.WRITE,
516 Encoding encoding: UTF8}) { 524 Encoding encoding: UTF8,
525 bool flush: false}) {
517 try { 526 try {
518 return writeAsBytes(encoding.encode(contents), mode: mode); 527 return writeAsBytes(encoding.encode(contents), mode: mode, flush: flush);
519 } catch (e) { 528 } catch (e) {
520 return new Future.error(e); 529 return new Future.error(e);
521 } 530 }
522 } 531 }
523 532
524 void writeAsStringSync(String contents, 533 void writeAsStringSync(String contents,
525 {FileMode mode: FileMode.WRITE, 534 {FileMode mode: FileMode.WRITE,
526 Encoding encoding: UTF8}) { 535 Encoding encoding: UTF8,
527 writeAsBytesSync(encoding.encode(contents), mode: mode); 536 bool flush: false}) {
537 writeAsBytesSync(encoding.encode(contents), mode: mode, flush: flush);
528 } 538 }
529 539
530 String toString() => "File: '$path'"; 540 String toString() => "File: '$path'";
531 541
532 static throwIfError(Object result, String msg, String path) { 542 static throwIfError(Object result, String msg, String path) {
533 if (result is OSError) { 543 if (result is OSError) {
534 throw new FileSystemException(msg, path, result); 544 throw new FileSystemException(msg, path, result);
535 } 545 }
536 } 546 }
537 } 547 }
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 889
880 void _checkAvailable() { 890 void _checkAvailable() {
881 if (_asyncDispatched) { 891 if (_asyncDispatched) {
882 throw new FileSystemException("An async operation is currently pending", p ath); 892 throw new FileSystemException("An async operation is currently pending", p ath);
883 } 893 }
884 if (closed) { 894 if (closed) {
885 throw new FileSystemException("File closed", path); 895 throw new FileSystemException("File closed", path);
886 } 896 }
887 } 897 }
888 } 898 }
OLDNEW
« 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