Skip to content

Commit b4db004

Browse files
benjamingrbengl
authored andcommitted
fs: fix writev empty array error behavior
PR-URL: #41919 Fixes: #41910 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Minwoo Jung <[email protected]>
1 parent 43a5161 commit b4db004

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/internal/fs/promises.js

+4
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ async function writev(handle, buffers, position) {
596596
if (typeof position !== 'number')
597597
position = null;
598598

599+
if (buffers.length === 0) {
600+
return { bytesWritten: 0, buffers };
601+
}
602+
599603
const bytesWritten = (await binding.writeBuffers(handle.fd, buffers, position,
600604
kUsePromises)) || 0;
601605
return { bytesWritten, buffers };

test/parallel/test-fs-writev-promises.js

+9
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,13 @@ tmpdir.refresh();
4747
assert(Buffer.concat(bufferArr).equals(await fs.readFile(filename)));
4848
handle.close();
4949
}
50+
51+
{
52+
// Writev with empty array behavior
53+
const handle = await fs.open(getFileName(), 'w');
54+
const result = await handle.writev([]);
55+
assert.strictEqual(result.bytesWritten, 0);
56+
assert.strictEqual(result.buffers.length, 0);
57+
handle.close();
58+
}
5059
})().then(common.mustCall());

0 commit comments

Comments
 (0)