Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! fs: add bufferSize option to fs.opendir()
  • Loading branch information
addaleax committed Oct 26, 2019
commit dc990cf02077006c5d8716d750dd6b21a226cb77
10 changes: 4 additions & 6 deletions lib/internal/fs/dir.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const {
getValidatedPath,
handleErrorFromBinding
} = require('internal/fs/utils');
const {
validateUint32
} = require('internal/validators');

const kDirHandle = Symbol('kDirHandle');
const kDirPath = Symbol('kDirPath');
Expand All @@ -47,12 +50,7 @@ class Dir {
})
};

if (typeof this[kDirOptions].bufferSize !== 'number' ||
!Number.isInteger(this[kDirOptions].bufferSize) ||
this[kDirOptions].bufferSize <= 0) {
throw new ERR_INVALID_OPT_VALUE('bufferSize',
this[kDirOptions].bufferSize);
}
validateUint32(this[kDirOptions].bufferSize, 'options.bufferSize', true);

this[kDirReadPromisified] =
internalUtil.promisify(this[kDirReadImpl]).bind(this, false);
Expand Down
19 changes: 13 additions & 6 deletions test/parallel/test-fs-opendir.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,19 @@ async function doAsyncIterThrowTest() {
doAsyncIterThrowTest().then(common.mustCall());

// Check error thrown on invalid values of bufferSize
for (const bufferSize of [-1, 0, 0.5, 1.5, Infinity, NaN, '', '1', null]) {
assert.throws(() => fs.opendirSync(testDir, { bufferSize }),
{
message: /The value ".*" is invalid for option "bufferSize"/,
code: 'ERR_INVALID_OPT_VALUE'
});
for (const bufferSize of [-1, 0, 0.5, 1.5, Infinity, NaN]) {
assert.throws(
() => fs.opendirSync(testDir, { bufferSize }),
{
code: 'ERR_OUT_OF_RANGE'
});
}
for (const bufferSize of ['', '1', null]) {
assert.throws(
() => fs.opendirSync(testDir, { bufferSize }),
{
code: 'ERR_INVALID_ARG_TYPE'
});
}

// Check that passing a positive integer as bufferSize works
Expand Down