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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 } | 349 } |
350 return _IOService._dispatch(_FILE_OPEN, [path, mode._mode]).then((response) { | 350 return _IOService._dispatch(_FILE_OPEN, [path, mode._mode]).then((response) { |
351 if (_isErrorResponse(response)) { | 351 if (_isErrorResponse(response)) { |
352 throw _exceptionFromResponse(response, "Cannot open file", path); | 352 throw _exceptionFromResponse(response, "Cannot open file", path); |
353 } | 353 } |
354 return new _RandomAccessFile(response, path); | 354 return new _RandomAccessFile(response, path); |
355 }); | 355 }); |
356 } | 356 } |
357 | 357 |
358 Future<int> length() { | 358 Future<int> length() { |
359 return _IOService._dispatch(_FILE_LENGTH_FROM_PATH, [path]).then((response) { | 359 return _IOService._dispatch(_FILE_LENGTH_FROM_PATH, [path]).then((response) { |
Lasse Reichstein Nielsen
2015/05/26 11:20:12
While you are here: Long line?
Søren Gjesse
2015/05/26 14:51:14
Done.
| |
360 if (_isErrorResponse(response)) { | 360 if (_isErrorResponse(response)) { |
361 throw _exceptionFromResponse(response, | 361 throw _exceptionFromResponse(response, |
362 "Cannot retrieve length of file", | 362 "Cannot retrieve length of file", |
363 path); | 363 path); |
364 } | 364 } |
365 return response; | 365 return response; |
366 }); | 366 }); |
367 } | 367 } |
368 | 368 |
369 | 369 |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
765 _totalWritten++; | 765 _totalWritten++; |
766 return result; | 766 return result; |
767 } | 767 } |
768 | 768 |
769 Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]) { | 769 Future<RandomAccessFile> writeFrom(List<int> buffer, [int start, int end]) { |
770 if ((buffer is !List && buffer is !ByteData) || | 770 if ((buffer is !List && buffer is !ByteData) || |
771 (start != null && start is !int) || | 771 (start != null && start is !int) || |
772 (end != null && end is !int)) { | 772 (end != null && end is !int)) { |
773 throw new ArgumentError("Invalid arguments to writeFrom"); | 773 throw new ArgumentError("Invalid arguments to writeFrom"); |
774 } | 774 } |
775 | 775 if (start == null) start = 0; |
Lasse Reichstein Nielsen
2015/05/26 11:20:12
Why not just make 0 the default value for the `sta
Søren Gjesse
2015/05/26 14:51:15
Done. _checkReadWriteListArguments actually just c
| |
776 if (end == null) end = buffer.length; | |
777 if (end == start) return; | |
778 _checkReadWriteListArguments(buffer.length, start, end); | |
776 _BufferAndStart result; | 779 _BufferAndStart result; |
777 try { | 780 try { |
778 result = _ensureFastAndSerializableByteData(buffer, start, end); | 781 result = _ensureFastAndSerializableByteData(buffer, start, end); |
779 } catch (e) { | 782 } catch (e) { |
780 return new Future.error(e); | 783 return new Future.error(e); |
781 } | 784 } |
782 | 785 |
783 List request = new List(4); | 786 List request = new List(4); |
784 request[0] = _id; | 787 request[0] = _id; |
785 request[1] = result.buffer; | 788 request[1] = result.buffer; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1042 void _checkAvailable() { | 1045 void _checkAvailable() { |
1043 if (_asyncDispatched) { | 1046 if (_asyncDispatched) { |
1044 throw new FileSystemException("An async operation is currently pending", | 1047 throw new FileSystemException("An async operation is currently pending", |
1045 path); | 1048 path); |
1046 } | 1049 } |
1047 if (closed) { | 1050 if (closed) { |
1048 throw new FileSystemException("File closed", path); | 1051 throw new FileSystemException("File closed", path); |
1049 } | 1052 } |
1050 } | 1053 } |
1051 } | 1054 } |
OLD | NEW |