mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
Add posix.truncate()
This commit is contained in:
1 parent
77145ba229
commit
76c1805c67
3 files changed
+36
No files matched your search
@@ -53,6 +53,7 @@ static int After(eio_req *req) {
|
||||
case EIO_UNLINK:
|
||||
case EIO_RMDIR:
|
||||
case EIO_MKDIR:
|
||||
case EIO_FTRUNCATE:
|
||||
argc = 0;
|
||||
break;
|
||||
|
||||
@@ -202,6 +203,25 @@ static Handle<Value> Rename(const Arguments& args) {
|
||||
}
|
||||
}
|
||||
|
||||
static Handle<Value> Truncate(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
if (args.Length() < 2 || !args[0]->IsInt32()) {
|
||||
return THROW_BAD_ARGS;
|
||||
}
|
||||
|
||||
int fd = args[0]->Int32Value();
|
||||
off_t len = args[1]->Uint32Value();
|
||||
|
||||
if (args[2]->IsFunction()) {
|
||||
ASYNC_CALL(ftruncate, args[2], fd, len)
|
||||
} else {
|
||||
int ret = ftruncate(fd, len);
|
||||
if (ret != 0) return ThrowException(errno_exception(errno));
|
||||
return Undefined();
|
||||
}
|
||||
}
|
||||
|
||||
static Handle<Value> Unlink(const Arguments& args) {
|
||||
HandleScope scope;
|
||||
|
||||
@@ -412,6 +432,7 @@ void File::Initialize(Handle<Object> target) {
|
||||
NODE_SET_METHOD(target, "open", Open);
|
||||
NODE_SET_METHOD(target, "read", Read);
|
||||
NODE_SET_METHOD(target, "rename", Rename);
|
||||
NODE_SET_METHOD(target, "truncate", Truncate);
|
||||
NODE_SET_METHOD(target, "rmdir", RMDir);
|
||||
NODE_SET_METHOD(target, "mkdir", MKDir);
|
||||
NODE_SET_METHOD(target, "sendfile", SendFile);
|
||||
|
||||
Reference in new issue
Block a user