OLD | NEW |
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 | 7 |
8 class _FileStream extends Stream<List<int>> { | 8 class _FileStream extends Stream<List<int>> { |
9 // Stream controller. | 9 // Stream controller. |
10 StreamController<List<int>> _controller; | 10 StreamController<List<int>> _controller; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 _position += block.length; | 87 _position += block.length; |
88 if (_paused) { | 88 if (_paused) { |
89 _currentBlock = block; | 89 _currentBlock = block; |
90 } else { | 90 } else { |
91 _controller.add(block); | 91 _controller.add(block); |
92 _readBlock(); | 92 _readBlock(); |
93 } | 93 } |
94 }) | 94 }) |
95 .catchError((e) { | 95 .catchError((e) { |
96 if (!_unsubscribed) { | 96 if (!_unsubscribed) { |
97 _controller.signalError(e); | 97 _controller.addError(e); |
98 _closeFile().then((_) { _controller.close(); }); | 98 _closeFile().then((_) { _controller.close(); }); |
99 _unsubscribed = true; | 99 _unsubscribed = true; |
100 } | 100 } |
101 }); | 101 }); |
102 } | 102 } |
103 | 103 |
104 void _start() { | 104 void _start() { |
105 Future<RandomAccessFile> openFuture; | 105 Future<RandomAccessFile> openFuture; |
106 if (_path != null) { | 106 if (_path != null) { |
107 openFuture = new File(_path).open(FileMode.READ); | 107 openFuture = new File(_path).open(FileMode.READ); |
108 } else { | 108 } else { |
109 openFuture = new Future.immediate(_File._openStdioSync(0)); | 109 openFuture = new Future.immediate(_File._openStdioSync(0)); |
110 } | 110 } |
111 openFuture | 111 openFuture |
112 .then((RandomAccessFile opened) { | 112 .then((RandomAccessFile opened) { |
113 _openedFile = opened; | 113 _openedFile = opened; |
114 _readBlock(); | 114 _readBlock(); |
115 }) | 115 }) |
116 .catchError((e) { | 116 .catchError((e) { |
117 _controller.signalError(e); | 117 _controller.addError(e); |
118 _controller.close(); | 118 _controller.close(); |
119 }); | 119 }); |
120 } | 120 } |
121 | 121 |
122 void _resume() { | 122 void _resume() { |
123 _paused = false; | 123 _paused = false; |
124 if (_currentBlock != null) { | 124 if (_currentBlock != null) { |
125 _controller.add(_currentBlock); | 125 _controller.add(_currentBlock); |
126 _currentBlock = null; | 126 _currentBlock = null; |
127 } | 127 } |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 new FileIOException("File closed '$_path'")); | 1049 new FileIOException("File closed '$_path'")); |
1050 }); | 1050 }); |
1051 return completer.future; | 1051 return completer.future; |
1052 } | 1052 } |
1053 | 1053 |
1054 final String _path; | 1054 final String _path; |
1055 int _id; | 1055 int _id; |
1056 | 1056 |
1057 SendPort _fileService; | 1057 SendPort _fileService; |
1058 } | 1058 } |
OLD | NEW |