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

Function writeFileHandle

lib/internal/fs/promises.js:1129–1162  ·  view source on GitHub ↗
(filehandle, data, signal, encoding)

Source from the content-addressed store, hash-verified

1127}
1128
1129async function writeFileHandle(filehandle, data, signal, encoding) {
1130 checkAborted(signal);
1131 if (isCustomIterable(data)) {
1132 for await (const buf of data) {
1133 checkAborted(signal);
1134 const toWrite =
1135 isArrayBufferView(buf) ? buf : Buffer.from(buf, encoding || 'utf8');
1136 let remaining = toWrite.byteLength;
1137 while (remaining > 0) {
1138 const writeSize = MathMin(kWriteFileMaxChunkSize, remaining);
1139 const { bytesWritten } = await write(
1140 filehandle, toWrite, toWrite.byteLength - remaining, writeSize);
1141 remaining -= bytesWritten;
1142 checkAborted(signal);
1143 }
1144 }
1145 return;
1146 }
1147 data = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
1148 let remaining = data.byteLength;
1149 if (remaining === 0) return;
1150 do {
1151 checkAborted(signal);
1152 const { bytesWritten } =
1153 await write(filehandle, data, 0,
1154 MathMin(kWriteFileMaxChunkSize, data.byteLength));
1155 remaining -= bytesWritten;
1156 data = new Uint8Array(
1157 data.buffer,
1158 data.byteOffset + bytesWritten,
1159 data.byteLength - bytesWritten,
1160 );
1161 } while (remaining > 0);
1162}
1163
1164async function readFileHandleWithUserBuffer(filehandle, options, size) {
1165 const signal = options?.signal;

Callers 1

writeFileFunction · 0.85

Calls 4

isCustomIterableFunction · 0.85
checkAbortedFunction · 0.70
writeFunction · 0.70
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…