From c326614c8d9f368cbb13c7547ed1fdf4ef7b9d0e Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 26 May 2009 12:11:31 +0200 Subject: [PATCH] More docs. Add rmdir and unlink. --- src/file.cc | 34 ++++++++++++++++++++++++++++++---- website/node.html | 24 +++++++++++++++++++----- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/file.cc b/src/file.cc index f366ea6..7c69bf6 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 d0b5366..7095c3f 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

-- 2.7.4