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

Unified Diff: runtime/bin/file_impl.dart

Issue 8679005: Add truncate operation to File API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 fa6b971460e3761278c016fbfdb3501f42288d82..f7f2f9dcba243f45b2fffc79ff978f3424ecab48 100644
--- a/runtime/bin/file_impl.dart
+++ b/runtime/bin/file_impl.dart
@@ -292,6 +292,18 @@ class _SetPositionOperation extends _FileOperation {
}
+class _TruncateOperation extends _FileOperation {
+ _TruncateOperation(int this._id, int this._length);
+
+ void execute(ReceivePort port) {
+ _replyPort.send(_File._truncate(_id, _length), port.toSendPort());
+ }
+
+ int _id;
+ int _length;
+}
+
+
class _LengthOperation extends _FileOperation {
_LengthOperation(int this._id);
@@ -435,7 +447,8 @@ 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 bool _setPosition(int id, int position) native "File_SetPosition";
+ static bool _truncate(int id, int length) native "File_Truncate";
static int _length(int id) native "File_Length";
static int _flush(int id) native "File_Flush";
static bool _create(String name) native "File_Create";
@@ -819,11 +832,11 @@ class _File implements File {
var handler =
(_setPositionHandler != null) ? _setPositionHandler : () => null;
var handleSetPositionResult = (result, ignored) {
- if (result == -1 && _errorHandler != null) {
+ if (result == false && _errorHandler != null) {
_errorHandler("setPosition failed");
return;
}
- handler(result);
+ handler();
};
var operation = new _SetPositionOperation(_id, position);
_scheduler.enqueue(operation, handleSetPositionResult);
@@ -834,12 +847,36 @@ class _File implements File {
throw new FileIOException(
"Mixed use of synchronous and asynchronous API");
}
- int result = _setPosition(_id, position);
- if (result == -1) {
+ bool result = _setPosition(_id, position);
+ if (result == false) {
throw new FileIOException("setPosition failed");
}
}
+ void truncate(int length) {
+ _asyncUsed = true;
+ var handler = (_truncateHandler != null) ? _truncateHandler : () => null;
+ var handleTruncateResult = (result, ignored) {
+ if (result == false && _errorHandler != null) {
+ _errorHandler("truncate failed");
+ return;
+ }
+ handler();
+ };
+ var operation = new _TruncateOperation(_id, length);
+ _scheduler.enqueue(operation, handleTruncateResult);
+ }
+
+ void truncateSync(int length) {
+ if (_asyncUsed) {
+ throw new FileIOException(
+ "Mixed use of synchronous and asynchronous API");
+ }
+ bool result = _truncate(_id, length);
+ if (result == false) {
+ throw new FileIOException("truncate failed");
+ }
+ }
void length() {
_asyncUsed = true;
@@ -971,6 +1008,10 @@ class _File implements File {
_setPositionHandler = handler;
}
+ void set truncateHandler(void handler()) {
+ _truncateHandler = handler;
+ }
+
void set lengthHandler(void handler(int length)) {
_lengthHandler = handler;
}
@@ -1003,6 +1044,7 @@ class _File implements File {
var _noPendingWriteHandler;
var _positionHandler;
var _setPositionHandler;
+ var _truncateHandler;
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