From ca3883ad6059408c4708b616e020238d6552e556 Mon Sep 17 00:00:00 2001 From: pulkit-30 Date: Fri, 8 Dec 2023 00:21:08 +0530 Subject: [PATCH] fix suggestions --- ex.txt | 1 + index.mjs | 22 ++++++++++++++++++++++ lib/internal/fs/promises.js | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ex.txt create mode 100644 index.mjs diff --git a/ex.txt b/ex.txt new file mode 100644 index 00000000000000..70c379b63ffa07 --- /dev/null +++ b/ex.txt @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/index.mjs b/index.mjs new file mode 100644 index 00000000000000..c0d67b63a8d268 --- /dev/null +++ b/index.mjs @@ -0,0 +1,22 @@ +import fs from "fs/promises"; + +async function test() { + let path = './ex.txt'; + + let buf = Buffer.alloc(4); + let handle; + try { + handle = await fs.open(path); + { + let buf = Buffer.alloc(4); + let { bytesRead, buffer } = await handle.read(buf); + // let { bytesRead, buffer } = await handle.read(buf, {}); // It is behavior I would expect. + console.log(bytesRead); + console.log(buffer); + console.log(buf); + } + } finally { + await handle?.close(); + } +} +test(); \ No newline at end of file diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 0f1db035629c42..1e9573d0385fd0 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -670,7 +670,7 @@ async function read(handle, bufferOrParams, offset, length, position) { validateInteger(offset, 'offset', 0); } - length = length ?? buffer.byteLength - offset; + length ??= buffer.byteLength - offset; if (length === 0) return { __proto__: null, bytesRead: length, buffer };