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

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

Issue 16125005: Make new StreamController be async by default. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 7 years, 6 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/io/directory_impl.dart ('k') | sdk/lib/io/http_impl.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 29 matching lines...) Expand all
40 {void onError(error), 40 {void onError(error),
41 void onDone(), 41 void onDone(),
42 bool cancelOnError}) { 42 bool cancelOnError}) {
43 return _controller.stream.listen(onData, 43 return _controller.stream.listen(onData,
44 onError: onError, 44 onError: onError,
45 onDone: onDone, 45 onDone: onDone,
46 cancelOnError: cancelOnError); 46 cancelOnError: cancelOnError);
47 } 47 }
48 48
49 void _setupController() { 49 void _setupController() {
50 _controller = new StreamController<List<int>>( 50 _controller = new StreamController<List<int>>(sync: true,
51 onListen: _start, 51 onListen: _start,
52 onPause: () => _paused = true, 52 onPause: () => _paused = true,
53 onResume: _resume, 53 onResume: _resume,
54 onCancel: () { 54 onCancel: () {
55 _unsubscribed = true; 55 _unsubscribed = true;
56 _closeFile(); 56 _closeFile();
57 }); 57 });
58 } 58 }
59 59
60 Future _closeFile() { 60 Future _closeFile() {
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 481 }
482 482
483 String readAsStringSync({Encoding encoding: Encoding.UTF_8}) { 483 String readAsStringSync({Encoding encoding: Encoding.UTF_8}) {
484 List<int> bytes = readAsBytesSync(); 484 List<int> bytes = readAsBytesSync();
485 return _decodeString(bytes, encoding); 485 return _decodeString(bytes, encoding);
486 } 486 }
487 487
488 static List<String> _decodeLines(List<int> bytes, Encoding encoding) { 488 static List<String> _decodeLines(List<int> bytes, Encoding encoding) {
489 if (bytes.length == 0) return []; 489 if (bytes.length == 0) return [];
490 var list = []; 490 var list = [];
491 var controller = new StreamController(); 491 var controller = new StreamController(sync: true);
492 controller.stream 492 controller.stream
493 .transform(new StringDecoder(encoding)) 493 .transform(new StringDecoder(encoding))
494 .transform(new LineTransformer()) 494 .transform(new LineTransformer())
495 .listen((line) => list.add(line)); 495 .listen((line) => list.add(line));
496 controller.add(bytes); 496 controller.add(bytes);
497 controller.close(); 497 controller.close();
498 return list; 498 return list;
499 } 499 }
500 500
501 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}) { 501 Future<List<String>> readAsLines({Encoding encoding: Encoding.UTF_8}) {
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 977
978 Future _closedException() { 978 Future _closedException() {
979 return new Future.error(new FileIOException("File closed '$_path'")); 979 return new Future.error(new FileIOException("File closed '$_path'"));
980 } 980 }
981 981
982 final String _path; 982 final String _path;
983 int _id; 983 int _id;
984 984
985 SendPort _fileService; 985 SendPort _fileService;
986 } 986 }
OLDNEW
« no previous file with comments | « sdk/lib/io/directory_impl.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698