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

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

Issue 13680002: StreamConsumer has an addStream and a close functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update comments. Created 7 years, 8 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/async/stream.dart ('k') | sdk/lib/io/http_impl.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 6da4d9f4f2c0ddf5b412a19a544c0d58e2ef0bee..57b8cd13749d9c0412134188181bf30f3becf0b1 100644
--- a/sdk/lib/io/file_impl.dart
+++ b/sdk/lib/io/file_impl.dart
@@ -151,6 +151,7 @@ class _FileStreamConsumer extends StreamConsumer<List<int>, File> {
File _file;
Future<RandomAccessFile> _openFuture;
StreamSubscription _subscription;
+
_FileStreamConsumer(File this._file, FileMode mode) {
_openFuture = _file.open(mode: mode);
@@ -162,6 +163,10 @@ class _FileStreamConsumer extends StreamConsumer<List<int>, File> {
}
Future<File> consume(Stream<List<int>> stream) {
+ return addStream(stream).then((_) => close());
+ }
+
+ Future<File> addStream(Stream<List<int>> stream) {
Completer<File> completer = new Completer<File>();
_openFuture
.then((openedFile) {
@@ -176,15 +181,7 @@ class _FileStreamConsumer extends StreamConsumer<List<int>, File> {
});
},
onDone: () {
- // Wait for the file to close (and therefore flush) before
- // completing the future.
- openedFile.close()
- .then((_) {
- completer.complete(_file);
- })
- .catchError((e) {
- completer.completeError(e);
- });
+ completer.complete(_file);
},
onError: (e) {
openedFile.close();
@@ -197,6 +194,10 @@ class _FileStreamConsumer extends StreamConsumer<List<int>, File> {
});
return completer.future;
}
+
+ Future<File> close() {
+ return _openFuture.then((openedFile) => openedFile.close());
+ }
}
« no previous file with comments | « sdk/lib/async/stream.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698