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

Side by Side Diff: sdk/lib/io/file_impl.dart

Issue 154273003: Make std* blocking file-descriptors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update with bug. Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sdk/lib/_internal/pub/pub.status ('k') | sdk/lib/io/stdio.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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 183
184 _FileStreamConsumer.fromStdio(int fd) { 184 _FileStreamConsumer.fromStdio(int fd) {
185 assert(1 <= fd && fd <= 2); 185 assert(1 <= fd && fd <= 2);
186 _openFuture = new Future.value(_File._openStdioSync(fd)); 186 _openFuture = new Future.value(_File._openStdioSync(fd));
187 } 187 }
188 188
189 Future<File> addStream(Stream<List<int>> stream) { 189 Future<File> addStream(Stream<List<int>> stream) {
190 Completer<File> completer = new Completer<File>(); 190 Completer<File> completer = new Completer<File>();
191 _openFuture 191 _openFuture
192 .then((openedFile) { 192 .then((openedFile) {
193 void error(e, [StackTrace stackTrace]) {
194 _subscription.cancel();
195 openedFile.close();
196 completer.completeError(e, stackTrace);
197 }
193 _subscription = stream.listen( 198 _subscription = stream.listen(
194 (d) { 199 (d) {
195 _subscription.pause(); 200 _subscription.pause();
196 openedFile.writeFrom(d, 0, d.length) 201 try {
197 .then((_) => _subscription.resume()) 202 openedFile.writeFrom(d, 0, d.length)
198 .catchError((e) { 203 .then((_) => _subscription.resume(),
199 openedFile.close(); 204 onError: error);
200 completer.completeError(e); 205 } catch (e, stackTrace) {
201 }); 206 error(e, stackTrace);
207 }
202 }, 208 },
203 onDone: () { 209 onDone: () {
204 completer.complete(_file); 210 completer.complete(_file);
205 }, 211 },
206 onError: (e, [StackTrace stackTrace]) { 212 onError: error,
207 openedFile.close();
208 completer.completeError(e, stackTrace);
209 },
210 cancelOnError: true); 213 cancelOnError: true);
211 }) 214 })
212 .catchError((e) { 215 .catchError((e) {
213 completer.completeError(e); 216 completer.completeError(e);
214 }); 217 });
215 return completer.future; 218 return completer.future;
216 } 219 }
217 220
218 Future<File> close() => 221 Future<File> close() =>
219 _openFuture.then((openedFile) => openedFile.close()); 222 _openFuture.then((openedFile) => openedFile.close());
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 906
904 void _checkAvailable() { 907 void _checkAvailable() {
905 if (_asyncDispatched) { 908 if (_asyncDispatched) {
906 throw new FileSystemException("An async operation is currently pending", p ath); 909 throw new FileSystemException("An async operation is currently pending", p ath);
907 } 910 }
908 if (closed) { 911 if (closed) {
909 throw new FileSystemException("File closed", path); 912 throw new FileSystemException("File closed", path);
910 } 913 }
911 } 914 }
912 } 915 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/pub/pub.status ('k') | sdk/lib/io/stdio.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698