diff --git a/lib/internal/fs/dir.js b/lib/internal/fs/dir.js index ec0562843d5f5c..03de09e379ca71 100644 --- a/lib/internal/fs/dir.js +++ b/lib/internal/fs/dir.js @@ -166,18 +166,22 @@ class Dir { pathModule.toNamespacedPath(dirent.path), this[kDirOptions].encoding, undefined, - ctx, + ctx ); handleErrorFromBinding(ctx); - const result = handle.read( - this[kDirOptions].encoding, - this[kDirOptions].bufferSize, - undefined, - ctx, - ); + while (true) { + const result = handle.read( + this[kDirOptions].encoding, + this[kDirOptions].bufferSize, + undefined, + ctx, + ); - if (result) { - this.processReadResult(dirent.path, result); + if (result) { + this.processReadResult(dirent.path, result); + } else { + break; + } } handle.close(undefined, ctx); @@ -206,7 +210,7 @@ class Dir { this[kDirOptions].encoding, this[kDirOptions].bufferSize, undefined, - ctx, + ctx ); handleErrorFromBinding(ctx);