diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-10-25 17:17:07 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2019-10-31 13:34:45 +0300 |
commit | 07b5584a3f2c8bbacdc23712e4e094f1ec42868d (patch) | |
tree | c62db1a49a9e0ab50e68cc4cfeefa9c5a500fa87 /src/node_dir.cc | |
parent | e4ab6fced1445c03176d3ce7c394c74ec4f3269b (diff) |
fs: add `bufferSize` option to `fs.opendir()`
Add an option that controls the size of the internal
buffer.
Fixes: https://github.com/nodejs/node/issues/29941
PR-URL: https://github.com/nodejs/node/pull/30114
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_dir.cc')
-rw-r--r-- | src/node_dir.cc | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/node_dir.cc b/src/node_dir.cc index 382f00f56e6..ffef27f4521 100644 --- a/src/node_dir.cc +++ b/src/node_dir.cc @@ -36,6 +36,7 @@ using v8::Isolate; using v8::Local; using v8::MaybeLocal; using v8::Null; +using v8::Number; using v8::Object; using v8::ObjectTemplate; using v8::String; @@ -59,8 +60,8 @@ DirHandle::DirHandle(Environment* env, Local<Object> obj, uv_dir_t* dir) dir_(dir) { MakeWeak(); - dir_->nentries = arraysize(dirents_); - dir_->dirents = dirents_; + dir_->nentries = 0; + dir_->dirents = nullptr; } DirHandle* DirHandle::New(Environment* env, uv_dir_t* dir) { @@ -230,22 +231,31 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) { Isolate* isolate = env->isolate(); const int argc = args.Length(); - CHECK_GE(argc, 2); + CHECK_GE(argc, 3); const enum encoding encoding = ParseEncoding(isolate, args[0], UTF8); DirHandle* dir; ASSIGN_OR_RETURN_UNWRAP(&dir, args.Holder()); - FSReqBase* req_wrap_async = GetReqWrap(env, args[1]); - if (req_wrap_async != nullptr) { // dir.read(encoding, req) + CHECK(args[1]->IsNumber()); + uint64_t buffer_size = args[1].As<Number>()->Value(); + + if (buffer_size != dir->dirents_.size()) { + dir->dirents_.resize(buffer_size); + dir->dir_->nentries = buffer_size; + dir->dir_->dirents = dir->dirents_.data(); + } + + FSReqBase* req_wrap_async = GetReqWrap(env, args[2]); + if (req_wrap_async != nullptr) { // dir.read(encoding, bufferSize, req) AsyncCall(env, req_wrap_async, args, "readdir", encoding, AfterDirRead, uv_fs_readdir, dir->dir()); - } else { // dir.read(encoding, undefined, ctx) - CHECK_EQ(argc, 3); + } else { // dir.read(encoding, bufferSize, undefined, ctx) + CHECK_EQ(argc, 4); FSReqWrapSync req_wrap_sync; FS_DIR_SYNC_TRACE_BEGIN(readdir); - int err = SyncCall(env, args[2], &req_wrap_sync, "readdir", uv_fs_readdir, + int err = SyncCall(env, args[3], &req_wrap_sync, "readdir", uv_fs_readdir, dir->dir()); FS_DIR_SYNC_TRACE_END(readdir); if (err < 0) { |