diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 6a0ce4d05c6b87..fbc4de640ade3c 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -596,6 +596,10 @@ async function writev(handle, buffers, position) { if (typeof position !== 'number') position = null; + if (buffers.length === 0) { + return { bytesWritten: 0, buffers }; + } + const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position, kUsePromises)) || 0; return { bytesWritten, buffers }; diff --git a/test/parallel/test-fs-writev-promises.js b/test/parallel/test-fs-writev-promises.js index 7c610adb4e50c2..650f00dae74b69 100644 --- a/test/parallel/test-fs-writev-promises.js +++ b/test/parallel/test-fs-writev-promises.js @@ -47,4 +47,13 @@ tmpdir.refresh(); assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename))); handle.close(); } + + { + // Writev with empty array behavior + const handle = await fs.open(getFileName(), 'w'); + const result = await handle.writev([]); + assert.strictEqual(result.bytesWritten, 0); + assert.strictEqual(result.buffers.length, 0); + handle.close(); + } })().then(common.mustCall());