MCPcopy Index your code
hub / github.com/nodejs/node / writeSync

Function writeSync

lib/fs.js:1079–1130  ·  view source on GitHub ↗

* Synchronously writes `buffer` to the * specified `fd` (file descriptor). * @param {number} fd * @param {Buffer | TypedArray | DataView | string} buffer * @param {{ * offset?: number; * length?: number; * position?: number | null; * }} [offsetOrOptions] * @param {number} [length]

(fd, buffer, offsetOrOptions, length, position)

Source from the content-addressed store, hash-verified

1077 * @returns {number}
1078 */
1079function writeSync(fd, buffer, offsetOrOptions, length, position) {
1080 const ctx = {};
1081 let result;
1082
1083 let offset = offsetOrOptions;
1084 if (isArrayBufferView(buffer)) {
1085 if (typeof offset === 'object') {
1086 ({
1087 offset = 0,
1088 length = buffer.byteLength - offset,
1089 position = null,
1090 } = offsetOrOptions ?? kEmptyObject);
1091 }
1092 if (position === undefined)
1093 position = null;
1094 if (offset == null) {
1095 offset = 0;
1096 } else {
1097 validateInteger(offset, 'offset', 0);
1098 }
1099 if (typeof length !== 'number')
1100 length = buffer.byteLength - offset;
1101 validateOffsetLengthWrite(offset, length, buffer.byteLength);
1102
1103 const h = vfsState.handlers;
1104 if (h !== null) {
1105 const vfsResult = h.writeSync(fd, buffer, offset, length, position);
1106 if (vfsResult !== undefined) return vfsResult;
1107 }
1108
1109 result = binding.writeBuffer(fd, buffer, offset, length, position,
1110 undefined, ctx);
1111 } else {
1112 validateStringAfterArrayBufferView(buffer, 'buffer');
1113 validateEncoding(buffer, length);
1114
1115 if (offset === undefined)
1116 offset = null;
1117
1118 const h = vfsState.handlers;
1119 if (h !== null) {
1120 const bufAsBuffer = Buffer.from(buffer, length);
1121 const vfsResult = h.writeSync(fd, bufAsBuffer, 0, bufAsBuffer.length, offset);
1122 if (vfsResult !== undefined) return vfsResult;
1123 }
1124
1125 result = binding.writeString(fd, buffer, offset, length,
1126 undefined, ctx);
1127 }
1128 handleErrorFromBinding(ctx);
1129 return result;
1130}
1131
1132/**
1133 * Writes an array of `ArrayBufferView`s to the

Callers 2

resolveFunction · 0.90
loadFunction · 0.90

Calls 3

handleErrorFromBindingFunction · 0.50
writeSyncMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…