Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: runtime/bin/file_impl.dart

Issue 8578003: Implement setPosition on File to seek to a byte position. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class _FileInputStream implements FileInputStream { 5 class _FileInputStream implements FileInputStream {
6 _FileInputStream(File file) { 6 _FileInputStream(File file) {
7 _file = new File(file.name); 7 _file = new File(file.name);
8 _file.openSync(); 8 _file.openSync();
9 } 9 }
10 10
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 _PositionOperation(int this._id); 273 _PositionOperation(int this._id);
274 274
275 void execute(ReceivePort port) { 275 void execute(ReceivePort port) {
276 _replyPort.send(_File._position(_id), port.toSendPort()); 276 _replyPort.send(_File._position(_id), port.toSendPort());
277 } 277 }
278 278
279 int _id; 279 int _id;
280 } 280 }
281 281
282 282
283 class _SetPositionOperation extends _FileOperation {
284 _SetPositionOperation(int this._id, int this._position);
285
286 void execute(ReceivePort port) {
287 _replyPort.send(_File._setPosition(_id, _position), port.toSendPort());
288 }
289
290 int _id;
291 int _position;
292 }
293
294
283 class _LengthOperation extends _FileOperation { 295 class _LengthOperation extends _FileOperation {
284 _LengthOperation(int this._id); 296 _LengthOperation(int this._id);
285 297
286 void execute(ReceivePort port) { 298 void execute(ReceivePort port) {
287 _replyPort.send(_File._length(_id), port.toSendPort()); 299 _replyPort.send(_File._length(_id), port.toSendPort());
288 } 300 }
289 301
290 int _id; 302 int _id;
291 } 303 }
292 304
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 static int _open(String name, bool writable) native "File_Open"; 417 static int _open(String name, bool writable) native "File_Open";
406 static int _close(int id) native "File_Close"; 418 static int _close(int id) native "File_Close";
407 static int _readByte(int id) native "File_ReadByte"; 419 static int _readByte(int id) native "File_ReadByte";
408 static int _readList(int id, List<int> buffer, int offset, int bytes) 420 static int _readList(int id, List<int> buffer, int offset, int bytes)
409 native "File_ReadList"; 421 native "File_ReadList";
410 static int _writeByte(int id, int value) native "File_WriteByte"; 422 static int _writeByte(int id, int value) native "File_WriteByte";
411 static int _writeList(int id, List<int> buffer, int offset, int bytes) 423 static int _writeList(int id, List<int> buffer, int offset, int bytes)
412 native "File_WriteList"; 424 native "File_WriteList";
413 static int _writeString(int id, String string) native "File_WriteString"; 425 static int _writeString(int id, String string) native "File_WriteString";
414 static int _position(int id) native "File_Position"; 426 static int _position(int id) native "File_Position";
427 static int _setPosition(int id, int position) native "File_SetPosition";
415 static int _length(int id) native "File_Length"; 428 static int _length(int id) native "File_Length";
416 static int _flush(int id) native "File_Flush"; 429 static int _flush(int id) native "File_Flush";
417 static bool _create(String name) native "File_Create"; 430 static bool _create(String name) native "File_Create";
418 static String _fullPath(String name) native "File_FullPath"; 431 static String _fullPath(String name) native "File_FullPath";
419 432
420 static int _checkReadWriteListArguments(int length, int offset, int bytes) { 433 static int _checkReadWriteListArguments(int length, int offset, int bytes) {
421 if (offset < 0) return offset; 434 if (offset < 0) return offset;
422 if (bytes < 0) return bytes; 435 if (bytes < 0) return bytes;
423 if ((offset + bytes) > length) return offset + bytes; 436 if ((offset + bytes) > length) return offset + bytes;
424 return 0; 437 return 0;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 throw new FileIOException( 765 throw new FileIOException(
753 "Mixed use of synchronous and asynchronous API"); 766 "Mixed use of synchronous and asynchronous API");
754 } 767 }
755 int result = _position(_id); 768 int result = _position(_id);
756 if (result == -1) { 769 if (result == -1) {
757 throw new FileIOException("position failed"); 770 throw new FileIOException("position failed");
758 } 771 }
759 return result; 772 return result;
760 } 773 }
761 774
775 void setPosition(int position) {
776 _asyncUsed = true;
777 var handler =
778 (_setPositionHandler != null) ? _setPositionHandler : () => null;
779 var handleSetPositionResult = (result, ignored) {
780 if (result == -1 && _errorHandler != null) {
781 _errorHandler("setPosition failed");
782 return;
783 }
784 handler(result);
785 };
786 var operation = new _SetPositionOperation(_id, position);
787 _scheduler.enqueue(operation, handleSetPositionResult);
788 }
789
790 void setPositionSync(int position) {
791 if (_asyncUsed) {
792 throw new FileIOException(
793 "Mixed use of synchronous and asynchronous API");
794 }
795 int result = _setPosition(_id, position);
796 if (result == -1) {
797 throw new FileIOException("setPosition failed");
798 }
799 }
800
801
762 void length() { 802 void length() {
763 _asyncUsed = true; 803 _asyncUsed = true;
764 var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null; 804 var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null;
765 var handleLengthResult = (result, ignored) { 805 var handleLengthResult = (result, ignored) {
766 if (result == -1 && _errorHandler != null) { 806 if (result == -1 && _errorHandler != null) {
767 _errorHandler("length failed"); 807 _errorHandler("length failed");
768 return; 808 return;
769 } 809 }
770 handler(result); 810 handler(result);
771 }; 811 };
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } 914 }
875 915
876 void set noPendingWriteHandler(void handler()) { 916 void set noPendingWriteHandler(void handler()) {
877 _noPendingWriteHandler = handler; 917 _noPendingWriteHandler = handler;
878 } 918 }
879 919
880 void set positionHandler(void handler(int pos)) { 920 void set positionHandler(void handler(int pos)) {
881 _positionHandler = handler; 921 _positionHandler = handler;
882 } 922 }
883 923
924 void set setPositionHandler(void handler()) {
925 _setPositionHandler = handler;
926 }
927
884 void set lengthHandler(void handler(int length)) { 928 void set lengthHandler(void handler(int length)) {
885 _lengthHandler = handler; 929 _lengthHandler = handler;
886 } 930 }
887 931
888 void set flushHandler(void handler()) { 932 void set flushHandler(void handler()) {
889 _flushHandler = handler; 933 _flushHandler = handler;
890 } 934 }
891 935
892 void set fullPathHandler(void handler(String)) { 936 void set fullPathHandler(void handler(String)) {
893 _fullPathHandler = handler; 937 _fullPathHandler = handler;
(...skipping 10 matching lines...) Expand all
904 _FileOperationScheduler _scheduler; 948 _FileOperationScheduler _scheduler;
905 949
906 var _existsHandler; 950 var _existsHandler;
907 var _createHandler; 951 var _createHandler;
908 var _openHandler; 952 var _openHandler;
909 var _closeHandler; 953 var _closeHandler;
910 var _readByteHandler; 954 var _readByteHandler;
911 var _readListHandler; 955 var _readListHandler;
912 var _noPendingWriteHandler; 956 var _noPendingWriteHandler;
913 var _positionHandler; 957 var _positionHandler;
958 var _setPositionHandler;
914 var _lengthHandler; 959 var _lengthHandler;
915 var _flushHandler; 960 var _flushHandler;
916 var _fullPathHandler; 961 var _fullPathHandler;
917 var _errorHandler; 962 var _errorHandler;
918 } 963 }
OLDNEW
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698