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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/file.dart ('k') | runtime/bin/file_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/file_impl.dart
diff --git a/runtime/bin/file_impl.dart b/runtime/bin/file_impl.dart
index 4cc7215ae3f8186dc1f5cfc27c442d936fb3f525..d19f34484a43768798ef52507813aa3c84f72e90 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,33 @@ class _File implements File {
return result;
}
+ void setPosition(int position) {
+ _asyncUsed = true;
+ var handler =
+ (_setPositionHandler != null) ? _setPositionHandler : () => null;
+ 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 +921,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 +955,7 @@ class _File implements File {
var _readListHandler;
var _noPendingWriteHandler;
var _positionHandler;
+ var _setPositionHandler;
var _lengthHandler;
var _flushHandler;
var _fullPathHandler;
« 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