| 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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 return result; | 690 return result; |
| 691 } | 691 } |
| 692 | 692 |
| 693 Future<int> readInto(List<int> buffer, [int start = 0, int end]) { | 693 Future<int> readInto(List<int> buffer, [int start = 0, int end]) { |
| 694 if (buffer is !List || | 694 if (buffer is !List || |
| 695 (start != null && start is !int) || | 695 (start != null && start is !int) || |
| 696 (end != null && end is !int)) { | 696 (end != null && end is !int)) { |
| 697 throw new ArgumentError(); | 697 throw new ArgumentError(); |
| 698 } | 698 } |
| 699 end = RangeError.checkValidRange(start, end, buffer.length); | 699 end = RangeError.checkValidRange(start, end, buffer.length); |
| 700 if (end == start) return 0; | 700 if (end == start) return new Future.value(0); |
| 701 int length = end - start; | 701 int length = end - start; |
| 702 return _dispatch(_FILE_READ_INTO, [_id, length]).then((response) { | 702 return _dispatch(_FILE_READ_INTO, [_id, length]).then((response) { |
| 703 if (_isErrorResponse(response)) { | 703 if (_isErrorResponse(response)) { |
| 704 throw _exceptionFromResponse(response, "readInto failed", path); | 704 throw _exceptionFromResponse(response, "readInto failed", path); |
| 705 } | 705 } |
| 706 var read = response[1]; | 706 var read = response[1]; |
| 707 var data = response[2]; | 707 var data = response[2]; |
| 708 buffer.setRange(start, start + read, data); | 708 buffer.setRange(start, start + read, data); |
| 709 _readCount++; | 709 _readCount++; |
| 710 _totalRead += read; | 710 _totalRead += read; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 } | 763 } |
| 764 | 764 |
| 765 Future<RandomAccessFile> writeFrom( | 765 Future<RandomAccessFile> writeFrom( |
| 766 List<int> buffer, [int start = 0, int end]) { | 766 List<int> buffer, [int start = 0, int end]) { |
| 767 if ((buffer is !List) || | 767 if ((buffer is !List) || |
| 768 (start != null && start is !int) || | 768 (start != null && start is !int) || |
| 769 (end != null && end is !int)) { | 769 (end != null && end is !int)) { |
| 770 throw new ArgumentError("Invalid arguments to writeFrom"); | 770 throw new ArgumentError("Invalid arguments to writeFrom"); |
| 771 } | 771 } |
| 772 end = RangeError.checkValidRange(start, end, buffer.length); | 772 end = RangeError.checkValidRange(start, end, buffer.length); |
| 773 if (end == start) return; | 773 if (end == start) return new Future.value(this); |
| 774 _BufferAndStart result; | 774 _BufferAndStart result; |
| 775 try { | 775 try { |
| 776 result = _ensureFastAndSerializableByteData(buffer, start, end); | 776 result = _ensureFastAndSerializableByteData(buffer, start, end); |
| 777 } catch (e) { | 777 } catch (e) { |
| 778 return new Future.error(e); | 778 return new Future.error(e); |
| 779 } | 779 } |
| 780 | 780 |
| 781 List request = new List(4); | 781 List request = new List(4); |
| 782 request[0] = _id; | 782 request[0] = _id; |
| 783 request[1] = result.buffer; | 783 request[1] = result.buffer; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 void _checkAvailable() { | 1038 void _checkAvailable() { |
| 1039 if (_asyncDispatched) { | 1039 if (_asyncDispatched) { |
| 1040 throw new FileSystemException("An async operation is currently pending", | 1040 throw new FileSystemException("An async operation is currently pending", |
| 1041 path); | 1041 path); |
| 1042 } | 1042 } |
| 1043 if (closed) { | 1043 if (closed) { |
| 1044 throw new FileSystemException("File closed", path); | 1044 throw new FileSystemException("File closed", path); |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 } | 1047 } |
| OLD | NEW |