fs: add writev() promises version by cjihrig · Pull Request #29186 · nodejs/node
Expand Up
@@ -72,6 +72,7 @@ const {
stringToFlags,
stringToSymlinkType,
toUnixTimestamp,
validateBufferArray,
validateOffsetLengthRead,
validateOffsetLengthWrite,
validatePath,
Expand Down
Expand Up
@@ -142,19 +143,6 @@ function maybeCallback(cb) {
throw new ERR_INVALID_CALLBACK(cb);
}
function isBuffersArray(value) { if (!Array.isArray(value)) return false;
for (var i = 0; i < value.length; i += 1) { if (!isArrayBufferView(value[i])) { return false; } }
return true; }
// Ensure that callbacks run in the global context. Only use this function // for callbacks that are passed to the binding layer, callbacks that are // invoked from JS already run in the proper scope. Expand Down Expand Up @@ -626,10 +614,7 @@ function writev(fd, buffers, position, callback) { }
validateInt32(fd, 'fd', 0);
if (!isBuffersArray(buffers)) { throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers); } validateBufferArray(buffers);
const req = new FSReqCallback(); req.oncomplete = wrapper; Expand All @@ -647,15 +632,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, { enumerable: false });
// fs.writevSync(fd, buffers[, position]); function writevSync(fd, buffers, position) {
validateInt32(fd, 'fd', 0); const ctx = {}; validateBufferArray(buffers);
if (!isBuffersArray(buffers)) { throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers); } const ctx = {};
if (typeof position !== 'number') position = null; Expand Down
function isBuffersArray(value) { if (!Array.isArray(value)) return false;
for (var i = 0; i < value.length; i += 1) { if (!isArrayBufferView(value[i])) { return false; } }
return true; }
// Ensure that callbacks run in the global context. Only use this function // for callbacks that are passed to the binding layer, callbacks that are // invoked from JS already run in the proper scope. Expand Down Expand Up @@ -626,10 +614,7 @@ function writev(fd, buffers, position, callback) { }
validateInt32(fd, 'fd', 0);
if (!isBuffersArray(buffers)) { throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers); } validateBufferArray(buffers);
const req = new FSReqCallback(); req.oncomplete = wrapper; Expand All @@ -647,15 +632,11 @@ Object.defineProperty(writev, internalUtil.customPromisifyArgs, { enumerable: false });
// fs.writevSync(fd, buffers[, position]); function writevSync(fd, buffers, position) {
validateInt32(fd, 'fd', 0); const ctx = {}; validateBufferArray(buffers);
if (!isBuffersArray(buffers)) { throw new ERR_INVALID_ARG_TYPE('buffers', 'ArrayBufferView[]', buffers); } const ctx = {};
if (typeof position !== 'number') position = null; Expand Down