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

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

Issue 12504006: Make IOSink implement StringSink (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed second round of review comments Created 7 years, 9 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 | « sdk/lib/io/file.dart ('k') | sdk/lib/io/http.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 0ba765cfb34a485ed91e21f7f778ea3d7f63dc95..72cb4d2d4f10241a18d968902de0e7aaf4345609 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -468,14 +468,15 @@ class _File extends _FileBase implements File {
return new _FileStream(_path);
}
- IOSink<File> openWrite([FileMode mode = FileMode.WRITE]) {
+ IOSink<File> openWrite({FileMode mode: FileMode.WRITE,
+ Encoding encoding: Encoding.UTF_8}) {
if (mode != FileMode.WRITE &&
mode != FileMode.APPEND) {
throw new FileIOException(
"Wrong FileMode. Use FileMode.WRITE or FileMode.APPEND");
}
var consumer = new _FileStreamConsumer(this, mode);
- return new IOSink<File>(consumer);
+ return new IOSink<File>(consumer, encoding: encoding);
}
Future<List<int>> readAsBytes() {
@@ -547,23 +548,14 @@ class _File extends _FileBase implements File {
Future<File> writeAsBytes(List<int> bytes,
[FileMode mode = FileMode.WRITE]) {
- Completer<File> completer = new Completer<File>();
try {
- var stream = openWrite(mode);
- stream.add(bytes);
- stream.close();
- stream.done
- .then((_) {
- completer.complete(this);
- })
- .catchError((e) {
- completer.completeError(e);
- });
+ IOSink<File> sink = openWrite(mode: mode);
+ sink.writeBytes(bytes);
+ sink.close();
+ return sink.done.then((_) => this);;
} catch (e) {
- Timer.run(() => completer.completeError(e));
- return completer.future;
+ return new Future.immediateError(e);
}
- return completer.future;
}
void writeAsBytesSync(List<int> bytes, [FileMode mode = FileMode.WRITE]) {
« no previous file with comments | « sdk/lib/io/file.dart ('k') | sdk/lib/io/http.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698