Chromium Code Reviews| Index: runtime/bin/file_impl.dart |
| diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart |
| index 4cc7215ae3f8186dc1f5cfc27c442d936fb3f525..4d0188c20b1eb6fc5d12b9736af5f22b5cdb1813 100644 |
| --- a/runtime/bin/file_impl.dart |
| +++ b/runtime/bin/file_impl.dart |
| @@ -280,6 +280,18 @@ class _PositionOperation extends _FileOperation { |
| } |
| +class _SetPositionOperation extends _FileOperation { |
| + _SetPositionOperation(int this._id, int this._position); |
| + |
| + void execute(ReceivePort port) { |
| + _replyPort.send(_File._setPosition(_id, _position), port.toSendPort()); |
| + } |
| + |
| + int _id; |
| + int _position; |
| +} |
| + |
| + |
| class _LengthOperation extends _FileOperation { |
| _LengthOperation(int this._id); |
| @@ -412,6 +424,7 @@ class _File implements File { |
| native "File_WriteList"; |
| static int _writeString(int id, String string) native "File_WriteString"; |
| static int _position(int id) native "File_Position"; |
| + static int _setPosition(int id, int position) native "File_SetPosition"; |
| static int _length(int id) native "File_Length"; |
| static int _flush(int id) native "File_Flush"; |
| static bool _create(String name) native "File_Create"; |
| @@ -759,6 +772,32 @@ class _File implements File { |
| return result; |
| } |
| + void setPosition(int position) { |
| + _asyncUsed = true; |
| + var handler = (_setPositionHandler != null) ? _setPositionHandler : () => null; |
|
Søren Gjesse
2011/11/16 15:24:11
Long line.
Mads Ager (google)
2011/11/16 15:49:17
Done.
|
| + var handleSetPositionResult = (result, ignored) { |
| + if (result == -1 && _errorHandler != null) { |
| + _errorHandler("setPosition failed"); |
| + return; |
| + } |
| + handler(result); |
| + }; |
| + var operation = new _SetPositionOperation(_id, position); |
| + _scheduler.enqueue(operation, handleSetPositionResult); |
| + } |
| + |
| + void setPositionSync(int position) { |
| + if (_asyncUsed) { |
| + throw new FileIOException( |
| + "Mixed use of synchronous and asynchronous API"); |
| + } |
| + int result = _setPosition(_id, position); |
| + if (result == -1) { |
| + throw new FileIOException("setPosition failed"); |
| + } |
| + } |
| + |
| + |
| void length() { |
| _asyncUsed = true; |
| var handler = (_lengthHandler != null) ? _lengthHandler : (pos) => null; |
| @@ -881,6 +920,10 @@ class _File implements File { |
| _positionHandler = handler; |
| } |
| + void set setPositionHandler(void handler()) { |
| + _setPositionHandler = handler; |
| + } |
| + |
| void set lengthHandler(void handler(int length)) { |
| _lengthHandler = handler; |
| } |
| @@ -911,6 +954,7 @@ class _File implements File { |
| var _readListHandler; |
| var _noPendingWriteHandler; |
| var _positionHandler; |
| + var _setPositionHandler; |
| var _lengthHandler; |
| var _flushHandler; |
| var _fullPathHandler; |