Skip to content

Commit 11892ad

Browse files
committed
minor fixes
1 parent 00952f7 commit 11892ad

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

lib/fs.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,8 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
821821
fd = getValidatedFd(fd);
822822

823823
let offset = offsetOrOptions;
824-
if (isArrayBuffer(buffer)) {
825-
buffer = new Uint8Array(buffer);
826-
}
827-
if (isArrayBufferView(buffer)) {
824+
const bufferToWrite = isArrayBuffer(buffer) ? new Uint8Array(buffer) : buffer;
825+
if (isArrayBufferView(bufferToWrite)) {
828826
callback = maybeCallback(callback || position || length || offset);
829827

830828
if (typeof offset === 'object') {

lib/internal/fs/promises.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,12 @@ async function write(handle, buffer, offsetOrOptions, length, position) {
653653
}
654654

655655
async function writev(handle, buffers, position) {
656-
if (buffers.length === 0) {
656+
const buffersToWrite = validateAndNormalizeBufferArray(buffers);
657+
658+
if (buffersToWrite.length === 0) {
657659
return { __proto__: null, bytesWritten: 0, buffers };
658660
}
659661

660-
const buffersToWrite = validateAndNormalizeBufferArray(buffers);
661-
662662
if (typeof position !== 'number')
663663
position = null;
664664

lib/internal/fs/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ const validateBufferArray = hideStackFrames((buffers, propName = 'buffers') => {
731731

732732
const validateAndNormalizeBufferArray = hideStackFrames((buffers, propName = 'buffers') => {
733733
if (!ArrayIsArray(buffers))
734-
throw new ERR_INVALID_ARG_TYPE(propName, 'ArrayBufferView[]', buffers);
734+
throw new ERR_INVALID_ARG_TYPE(propName, ['ArrayBufferView[]', 'ArrayBuffer[]'], buffers);
735735

736736
const output = [];
737737
for (let i = 0; i < buffers.length; i++) {
@@ -741,7 +741,7 @@ const validateAndNormalizeBufferArray = hideStackFrames((buffers, propName = 'bu
741741
} else if (isArrayBuffer(buffer)) {
742742
output.push(new Uint8Array(buffers[i]));
743743
} else {
744-
throw new ERR_INVALID_ARG_TYPE(propName, 'ArrayBufferView[]', buffers);
744+
throw new ERR_INVALID_ARG_TYPE(propName, ['ArrayBufferView[]', 'ArrayBuffer[]'], buffers);
745745
}
746746
}
747747
return output;
@@ -907,7 +907,7 @@ const validateStringAfterArrayBufferView = hideStackFrames((buffer, name) => {
907907
if (typeof buffer !== 'string') {
908908
throw new ERR_INVALID_ARG_TYPE(
909909
name,
910-
['string', 'Buffer', 'TypedArray', 'DataView'],
910+
['string', 'Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'],
911911
buffer
912912
);
913913
}

0 commit comments

Comments
 (0)