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 // 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 | 170 |
171 class _FileStreamConsumer extends StreamConsumer<List<int>> { | 171 class _FileStreamConsumer extends StreamConsumer<List<int>> { |
172 File _file; | 172 File _file; |
173 Future<RandomAccessFile> _openFuture; | 173 Future<RandomAccessFile> _openFuture; |
174 | 174 |
175 _FileStreamConsumer(File this._file, FileMode mode) { | 175 _FileStreamConsumer(File this._file, FileMode mode) { |
176 _openFuture = _file.open(mode: mode); | 176 _openFuture = _file.open(mode: mode); |
177 } | 177 } |
178 | 178 |
179 _FileStreamConsumer.fromStdio(int fd) { | |
180 assert(1 <= fd && fd <= 2); | |
181 _openFuture = new Future.value(_File._openStdioSync(fd)); | |
182 } | |
183 | |
184 Future<File> addStream(Stream<List<int>> stream) { | 179 Future<File> addStream(Stream<List<int>> stream) { |
185 Completer<File> completer = new Completer<File>.sync(); | 180 Completer<File> completer = new Completer<File>.sync(); |
186 _openFuture | 181 _openFuture |
187 .then((openedFile) { | 182 .then((openedFile) { |
188 var _subscription; | 183 var _subscription; |
189 void error(e, [StackTrace stackTrace]) { | 184 void error(e, [StackTrace stackTrace]) { |
190 _subscription.cancel(); | 185 _subscription.cancel(); |
191 openedFile.close(); | 186 openedFile.close(); |
192 completer.completeError(e, stackTrace); | 187 completer.completeError(e, stackTrace); |
193 } | 188 } |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 void _checkAvailable() { | 964 void _checkAvailable() { |
970 if (_asyncDispatched) { | 965 if (_asyncDispatched) { |
971 throw new FileSystemException("An async operation is currently pending", | 966 throw new FileSystemException("An async operation is currently pending", |
972 path); | 967 path); |
973 } | 968 } |
974 if (closed) { | 969 if (closed) { |
975 throw new FileSystemException("File closed", path); | 970 throw new FileSystemException("File closed", path); |
976 } | 971 } |
977 } | 972 } |
978 } | 973 } |
OLD | NEW |