Skip to content

Commit

Permalink
fs: fix writev empty array error behavior
Browse files Browse the repository at this point in the history
PR-URL: #41919
Fixes: #41910
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
benjamingr authored and bengl committed Feb 22, 2022
1 parent 43a5161 commit b4db004
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-fs-writev-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

0 comments on commit b4db004

Please sign in to comment.