* Writes an array of `ArrayBufferView`s to the * specified `fd` (file descriptor). * @param {number} fd * @param {ArrayBufferView[]} buffers * @param {number | null} [position] * @param {( * err?: Error, * bytesWritten?: number, * buffers?: ArrayBufferView[] * ) => any} callback *
(fd, buffers, position, callback)
| 1143 | * @returns {void} |
| 1144 | */ |
| 1145 | function writev(fd, buffers, position, callback) { |
| 1146 | function wrapper(err, written) { |
| 1147 | callback(err, written || 0, buffers); |
| 1148 | } |
| 1149 | |
| 1150 | fd = getValidatedFd(fd); |
| 1151 | validateBufferArray(buffers); |
| 1152 | callback ||= position; |
| 1153 | validateFunction(callback, 'cb'); |
| 1154 | |
| 1155 | if (buffers.length === 0) { |
| 1156 | process.nextTick(callback, null, 0, buffers); |
| 1157 | return; |
| 1158 | } |
| 1159 | |
| 1160 | if (typeof position !== 'number') |
| 1161 | position = null; |
| 1162 | |
| 1163 | const h = vfsState.handlers; |
| 1164 | if (h !== null) { |
| 1165 | const promise = h.writev(fd, buffers, position); |
| 1166 | if (promise !== undefined) { |
| 1167 | PromisePrototypeThen(promise, |
| 1168 | (written) => callback(null, written, buffers), callback); |
| 1169 | return; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | const req = new FSReqCallback(); |
| 1174 | req.oncomplete = wrapper; |
| 1175 | |
| 1176 | binding.writeBuffers(fd, buffers, position, req); |
| 1177 | } |
| 1178 | |
| 1179 | ObjectDefineProperty(writev, kCustomPromisifyArgsSymbol, { |
| 1180 | __proto__: null, |