Browse Source

Add node.fs.mkdir()

v0.7.4-release
Ryan 16 years ago
parent
commit
3736bf9f49
  1. 17
      src/file.cc
  2. 8
      src/file.h
  3. 5
      website/api.txt

17
src/file.cc

@ -82,6 +82,7 @@ EIOPromise::After (eio_req *req)
case EIO_RENAME:
case EIO_UNLINK:
case EIO_RMDIR:
case EIO_MKDIR:
argc = 0;
break;
@ -251,6 +252,21 @@ RMDir (const Arguments& args)
return scope.Close(EIOPromise::RMDir(*path));
}
static Handle<Value>
MKDir (const Arguments& args)
{
HandleScope scope;
if (args.Length() < 2 || !args[0]->IsString() || !args[1]->IsInt32()) {
return ThrowException(BAD_ARGUMENTS);
}
String::Utf8Value path(args[0]->ToString());
mode_t mode = static_cast<mode_t>(args[1]->Int32Value());
return scope.Close(EIOPromise::MKDir(*path, mode));
}
static Handle<Value>
ReadDir (const Arguments& args)
{
@ -369,6 +385,7 @@ File::Initialize (Handle<Object> target)
NODE_SET_METHOD(target, "read", Read);
NODE_SET_METHOD(target, "rename", Rename);
NODE_SET_METHOD(target, "rmdir", RMDir);
NODE_SET_METHOD(target, "mkdir", MKDir);
NODE_SET_METHOD(target, "readdir", ReadDir);
NODE_SET_METHOD(target, "stat", Stat);
NODE_SET_METHOD(target, "unlink", Unlink);

8
src/file.h

@ -93,6 +93,14 @@ class EIOPromise : public Promise {
return p->handle_;
}
static v8::Handle<v8::Object>
MKDir (const char *path, mode_t mode)
{
EIOPromise *p = Create();
p->req_ = eio_mkdir(path, mode, EIO_PRI_DEFAULT, After, p);
return p->handle_;
}
static v8::Handle<v8::Object>
ReadDir (const char *path)
{

5
website/api.txt

@ -453,6 +453,11 @@ node.fs.stat("/tmp/world").addCallback(function (stats) {
- on success: no parameters.
- on error: no parameters.
+node.fs.mkdir(path, mode)+ ::
See mkdir(2)
- on success: no parameters.
- on error: no parameters.
+node.fs.readdir(path)+ ::
Reads the contents of a directory.
- on success: One argument, an array containing the names (strings) of the

Loading…
Cancel
Save