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 <duhamelantoine1995@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
  • Loading branch information
benjamingr authored and danielleadams committed Apr 24, 2022
1 parent e21831b commit 257a7a5
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
Expand Up @@ -544,6 +544,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
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 257a7a5

Please sign in to comment.