Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SRHerzog committed Feb 17, 2023
1 parent d9bd41f commit 7b5fe63
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,8 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) {
fd = getValidatedFd(fd);

let offset = offsetOrOptions;
if (isArrayBuffer(buffer)) {
buffer = new Uint8Array(buffer);
}
if (isArrayBufferView(buffer)) {
const bufferToWrite = isArrayBuffer(buffer) ? new Uint8Array(buffer) : buffer;
if (isArrayBufferView(bufferToWrite)) {
callback = maybeCallback(callback || position || length || offset);

if (typeof offset === 'object') {
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,12 +653,12 @@ async function write(handle, buffer, offsetOrOptions, length, position) {
}

async function writev(handle, buffers, position) {
if (buffers.length === 0) {
const buffersToWrite = validateAndNormalizeBufferArray(buffers);

if (buffersToWrite.length === 0) {
return { __proto__: null, bytesWritten: 0, buffers };
}

const buffersToWrite = validateAndNormalizeBufferArray(buffers);

if (typeof position !== 'number')
position = null;

Expand Down
6 changes: 3 additions & 3 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ const validateBufferArray = hideStackFrames((buffers, propName = 'buffers') => {

const validateAndNormalizeBufferArray = hideStackFrames((buffers, propName = 'buffers') => {
if (!ArrayIsArray(buffers))
throw new ERR_INVALID_ARG_TYPE(propName, 'ArrayBufferView[]', buffers);
throw new ERR_INVALID_ARG_TYPE(propName, ['ArrayBufferView[]', 'ArrayBuffer[]'], buffers);

const output = [];
for (let i = 0; i < buffers.length; i++) {
Expand All @@ -741,7 +741,7 @@ const validateAndNormalizeBufferArray = hideStackFrames((buffers, propName = 'bu
} else if (isArrayBuffer(buffer)) {
output.push(new Uint8Array(buffers[i]));
} else {
throw new ERR_INVALID_ARG_TYPE(propName, 'ArrayBufferView[]', buffers);
throw new ERR_INVALID_ARG_TYPE(propName, ['ArrayBufferView[]', 'ArrayBuffer[]'], buffers);
}
}
return output;
Expand Down Expand Up @@ -907,7 +907,7 @@ const validateStringAfterArrayBufferView = hideStackFrames((buffer, name) => {
if (typeof buffer !== 'string') {
throw new ERR_INVALID_ARG_TYPE(
name,
['string', 'Buffer', 'TypedArray', 'DataView'],
['string', 'Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'],
buffer,
);
}
Expand Down

0 comments on commit 7b5fe63

Please sign in to comment.