diff --git a/src/file.cc b/src/file.cc index f366ea6583a..7c69bf69753 100644 --- a/src/file.cc +++ b/src/file.cc @@ -84,6 +84,30 @@ static Handle Rename (const Arguments& args) return Undefined(); } +DEFINE_SIMPLE_CB(Unlink) +static Handle Unlink (const Arguments& args) +{ + if (args.Length() < 1 || !args[0]->IsString()) + return ThrowException(BAD_ARGUMENTS); + HandleScope scope; + String::Utf8Value path(args[0]->ToString()); + MAKE_CALLBACK_PTR + eio_unlink(*path, EIO_PRI_DEFAULT, AfterUnlink, callback); + return Undefined(); +} + +DEFINE_SIMPLE_CB(RMDir) +static Handle RMDir (const Arguments& args) +{ + if (args.Length() < 1 || !args[0]->IsString()) + return ThrowException(BAD_ARGUMENTS); + HandleScope scope; + String::Utf8Value path(args[0]->ToString()); + MAKE_CALLBACK_PTR + eio_rmdir(*path, EIO_PRI_DEFAULT, AfterRMDir, callback); + return Undefined(); +} + static int AfterOpen (eio_req *req) { @@ -355,13 +379,15 @@ File::Initialize (Handle target) { HandleScope scope; - // file system methods - NODE_SET_METHOD(target, "rename", Rename); - NODE_SET_METHOD(target, "stat", Stat); + // POSIX Wrappers NODE_SET_METHOD(target, "close", Close); NODE_SET_METHOD(target, "open", Open); - NODE_SET_METHOD(target, "write", Write); NODE_SET_METHOD(target, "read", Read); + NODE_SET_METHOD(target, "rename", Rename); + NODE_SET_METHOD(target, "rmdir", RMDir); + NODE_SET_METHOD(target, "stat", Stat); + NODE_SET_METHOD(target, "unlink", Unlink); + NODE_SET_METHOD(target, "write", Write); NODE_SET_METHOD(target, "strerror", StrError); diff --git a/website/node.html b/website/node.html index d0b5366d5b7..7095c3f96c9 100644 --- a/website/node.html +++ b/website/node.html @@ -227,7 +227,7 @@ pool to execute file system calls.

This part of the API is split into two parts: simple wrappers around -standard POSIX file I/O functions, and a user-friendly File +standard POSIX file I/O functions and a user-friendly File object.

POSIX Wrappers

@@ -266,15 +266,29 @@ node.fs.rename("/tmp/hello", "/tmp/world", function (status) {
-
node.fs.rename(path1, path2, on_completion)
+
node.fs.rename(path1, path2, on_completion(status))
- on_completion(status) + rename(2)
-
node.fs.stat(path, on_completion)
+
node.fs.stat(path, on_completion(status, stats))
- on_completion(status, stat_object) + stat(2)
+ +
node.fs.unlink(path, on_completion(status))
+
+ unlink(2) +
+ +
node.fs.rmdir(path, on_completion(status))
+
+ rmdir(2) +
+

node.fs.File