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 class _FileStream extends Stream<List<int>> { | 10 class _FileStream extends Stream<List<int>> { |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 read(int bytes); | 610 read(int bytes); |
611 readInto(List<int> buffer, int start, int end); | 611 readInto(List<int> buffer, int start, int end); |
612 writeByte(int value); | 612 writeByte(int value); |
613 writeFrom(List<int> buffer, int start, int end); | 613 writeFrom(List<int> buffer, int start, int end); |
614 position(); | 614 position(); |
615 setPosition(int position); | 615 setPosition(int position); |
616 truncate(int length); | 616 truncate(int length); |
617 length(); | 617 length(); |
618 flush(); | 618 flush(); |
619 lock(int lock, int start, int end); | 619 lock(int lock, int start, int end); |
620 setTranslation(int translation); | |
621 } | |
622 | |
623 /** | |
624 * The translation mode of a File. | |
625 * | |
626 * Whether the data written to a file should be interpreted as text | |
627 * or binary data. This distinction is only meaningful on platforms that | |
628 * recognize a difference, in particular on Windows. | |
629 */ | |
630 enum _FileTranslation { | |
631 /// Data should be interpreted as text. | |
632 text, | |
633 | |
634 /// Data should be interpreted as binary data. | |
635 binary, | |
636 } | 620 } |
637 | 621 |
638 class _RandomAccessFile implements RandomAccessFile { | 622 class _RandomAccessFile implements RandomAccessFile { |
639 static bool _connectedResourceHandler = false; | 623 static bool _connectedResourceHandler = false; |
640 | 624 |
641 final String path; | 625 final String path; |
642 | 626 |
643 bool _asyncDispatched = false; | 627 bool _asyncDispatched = false; |
644 SendPort _fileService; | 628 SendPort _fileService; |
645 | 629 |
646 _FileResourceInfo _resourceInfo; | 630 _FileResourceInfo _resourceInfo; |
647 _RandomAccessFileOps _ops; | 631 _RandomAccessFileOps _ops; |
648 | 632 |
649 _FileTranslation _translation; | |
650 | |
651 _RandomAccessFile(int pointer, this.path) { | 633 _RandomAccessFile(int pointer, this.path) { |
652 _ops = new _RandomAccessFileOps(pointer); | 634 _ops = new _RandomAccessFileOps(pointer); |
653 _resourceInfo = new _FileResourceInfo(this); | 635 _resourceInfo = new _FileResourceInfo(this); |
654 _translation = _FileTranslation.binary; | |
655 _maybeConnectHandler(); | 636 _maybeConnectHandler(); |
656 } | 637 } |
657 | 638 |
658 void _maybePerformCleanup() { | 639 void _maybePerformCleanup() { |
659 if (closed) { | 640 if (closed) { |
660 _FileResourceInfo.FileClosed(_resourceInfo); | 641 _FileResourceInfo.FileClosed(_resourceInfo); |
661 } | 642 } |
662 } | 643 } |
663 | 644 |
664 _maybeConnectHandler() { | 645 _maybeConnectHandler() { |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 } | 1026 } |
1046 if (start == end) { | 1027 if (start == end) { |
1047 throw new ArgumentError(); | 1028 throw new ArgumentError(); |
1048 } | 1029 } |
1049 var result = _ops.lock(LOCK_UNLOCK, start, end); | 1030 var result = _ops.lock(LOCK_UNLOCK, start, end); |
1050 if (result is OSError) { | 1031 if (result is OSError) { |
1051 throw new FileSystemException('unlock failed', path, result); | 1032 throw new FileSystemException('unlock failed', path, result); |
1052 } | 1033 } |
1053 } | 1034 } |
1054 | 1035 |
1055 _FileTranslation get translation => _translation; | |
1056 | |
1057 void set translation(_FileTranslation translation) { | |
1058 if (_translation != translation) { | |
1059 _ops.setTranslation(translation.index); | |
1060 _translation = translation; | |
1061 } | |
1062 } | |
1063 | |
1064 bool closed = false; | 1036 bool closed = false; |
1065 | 1037 |
1066 // Calling this function will increase the reference count on the native | 1038 // Calling this function will increase the reference count on the native |
1067 // object that implements the file operations. It should only be called to | 1039 // object that implements the file operations. It should only be called to |
1068 // pass the pointer to the IO Service, which will decrement the reference | 1040 // pass the pointer to the IO Service, which will decrement the reference |
1069 // count when it is finished with it. | 1041 // count when it is finished with it. |
1070 int _pointer() => _ops.getPointer(); | 1042 int _pointer() => _ops.getPointer(); |
1071 | 1043 |
1072 Future _dispatch(int request, List data, {bool markClosed: false}) { | 1044 Future _dispatch(int request, List data, {bool markClosed: false}) { |
1073 if (closed) { | 1045 if (closed) { |
(...skipping 18 matching lines...) Expand all Loading... |
1092 void _checkAvailable() { | 1064 void _checkAvailable() { |
1093 if (_asyncDispatched) { | 1065 if (_asyncDispatched) { |
1094 throw new FileSystemException( | 1066 throw new FileSystemException( |
1095 "An async operation is currently pending", path); | 1067 "An async operation is currently pending", path); |
1096 } | 1068 } |
1097 if (closed) { | 1069 if (closed) { |
1098 throw new FileSystemException("File closed", path); | 1070 throw new FileSystemException("File closed", path); |
1099 } | 1071 } |
1100 } | 1072 } |
1101 } | 1073 } |
OLD | NEW |