@@ -36,6 +36,7 @@ using v8::Isolate;
36
36
using v8::Local;
37
37
using v8::MaybeLocal;
38
38
using v8::Null;
39
+ using v8::Number;
39
40
using v8::Object;
40
41
using v8::ObjectTemplate;
41
42
using v8::String;
@@ -59,8 +60,8 @@ DirHandle::DirHandle(Environment* env, Local<Object> obj, uv_dir_t* dir)
59
60
dir_ (dir) {
60
61
MakeWeak ();
61
62
62
- dir_->nentries = arraysize (dirents_) ;
63
- dir_->dirents = dirents_ ;
63
+ dir_->nentries = 0 ;
64
+ dir_->dirents = nullptr ;
64
65
}
65
66
66
67
DirHandle* DirHandle::New (Environment* env, uv_dir_t * dir) {
@@ -230,22 +231,31 @@ void DirHandle::Read(const FunctionCallbackInfo<Value>& args) {
230
231
Isolate* isolate = env->isolate ();
231
232
232
233
const int argc = args.Length ();
233
- CHECK_GE (argc, 2 );
234
+ CHECK_GE (argc, 3 );
234
235
235
236
const enum encoding encoding = ParseEncoding (isolate, args[0 ], UTF8);
236
237
237
238
DirHandle* dir;
238
239
ASSIGN_OR_RETURN_UNWRAP (&dir, args.Holder ());
239
240
240
- FSReqBase* req_wrap_async = GetReqWrap (env, args[1 ]);
241
- if (req_wrap_async != nullptr ) { // dir.read(encoding, req)
241
+ CHECK (args[1 ]->IsNumber ());
242
+ uint64_t buffer_size = args[1 ].As <Number>()->Value ();
243
+
244
+ if (buffer_size != dir->dirents_ .size ()) {
245
+ dir->dirents_ .resize (buffer_size);
246
+ dir->dir_ ->nentries = buffer_size;
247
+ dir->dir_ ->dirents = dir->dirents_ .data ();
248
+ }
249
+
250
+ FSReqBase* req_wrap_async = GetReqWrap (env, args[2 ]);
251
+ if (req_wrap_async != nullptr ) { // dir.read(encoding, bufferSize, req)
242
252
AsyncCall (env, req_wrap_async, args, " readdir" , encoding,
243
253
AfterDirRead, uv_fs_readdir, dir->dir ());
244
- } else { // dir.read(encoding, undefined, ctx)
245
- CHECK_EQ (argc, 3 );
254
+ } else { // dir.read(encoding, bufferSize, undefined, ctx)
255
+ CHECK_EQ (argc, 4 );
246
256
FSReqWrapSync req_wrap_sync;
247
257
FS_DIR_SYNC_TRACE_BEGIN (readdir);
248
- int err = SyncCall (env, args[2 ], &req_wrap_sync, " readdir" , uv_fs_readdir,
258
+ int err = SyncCall (env, args[3 ], &req_wrap_sync, " readdir" , uv_fs_readdir,
249
259
dir->dir ());
250
260
FS_DIR_SYNC_TRACE_END (readdir);
251
261
if (err < 0 ) {
0 commit comments