diff options
Diffstat (limited to 'lib/internal/fs/utils.js')
-rw-r--r-- | lib/internal/fs/utils.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 3b4ef8c423..6b50a60051 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -47,7 +47,8 @@ const { validateAbortSignal, validateBoolean, validateInt32, - validateUint32 + validateInteger, + validateUint32, } = require('internal/validators'); const pathModule = require('path'); const kType = Symbol('type'); @@ -818,6 +819,22 @@ const validateStringAfterArrayBufferView = hideStackFrames((buffer, name) => { ); }); +const validatePosition = hideStackFrames((position, name) => { + if (typeof position === 'number') { + validateInteger(position, 'position'); + } else if (typeof position === 'bigint') { + if (!(position >= -(2n ** 63n) && position <= 2n ** 63n - 1n)) { + throw new ERR_OUT_OF_RANGE('position', + `>= ${-(2n ** 63n)} && <= ${2n ** 63n - 1n}`, + position); + } + } else { + throw new ERR_INVALID_ARG_TYPE('position', + ['integer', 'bigint'], + position); + } +}); + module.exports = { assertEncoding, BigIntStats, // for testing @@ -841,6 +858,7 @@ module.exports = { validateOffsetLengthRead, validateOffsetLengthWrite, validatePath, + validatePosition, validateRmOptions, validateRmOptionsSync, validateRmdirOptions, |