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

Method write

deps/undici/undici.js:8172–8221  ·  view source on GitHub ↗

* @param {string|Uint8Array} chunk * @returns

(chunk)

Source from the content-addressed store, hash-verified

8170 * @returns
8171 */
8172 write(chunk) {
8173 const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this;
8174 if (socket[kError]) {
8175 throw socket[kError];
8176 }
8177 if (socket.destroyed) {
8178 return false;
8179 }
8180 const len = chunk instanceof Uint8Array ? chunk.byteLength : Buffer.byteLength(chunk);
8181 if (!len) {
8182 return true;
8183 }
8184 if (contentLength !== null && bytesWritten + len > contentLength) {
8185 if (client[kStrictContentLength]) {
8186 throw new RequestContentLengthMismatchError();
8187 }
8188 process.emitWarning(new RequestContentLengthMismatchError());
8189 }
8190 socket.cork();
8191 if (bytesWritten === 0) {
8192 if (!expectsPayload && request.reset !== false) {
8193 socket[kReset] = true;
8194 }
8195 if (contentLength === null) {
8196 socket.write(`${header}transfer-encoding: chunked\r
8197`, "latin1");
8198 } else {
8199 socket.write(`${header}content-length: ${contentLength}\r
8200\r
8201`, "latin1");
8202 }
8203 }
8204 if (contentLength === null) {
8205 socket.write(`\r
8206${len.toString(16)}\r
8207`, "latin1");
8208 }
8209 this.bytesWritten += len;
8210 const ret = socket.write(chunk);
8211 socket.uncork();
8212 request.onBodySent(chunk);
8213 if (!ret) {
8214 if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
8215 if (socket[kParser].timeout.refresh) {
8216 socket[kParser].timeout.refresh();
8217 }
8218 }
8219 }
8220 return ret;
8221 }
8222 /**
8223 * @returns {void}
8224 */

Callers 15

try_check_compilerFunction · 0.45
get_openssl_versionFunction · 0.45
cc_macrosFunction · 0.45
writeFunction · 0.45
updateProgressMethod · 0.45
mainFunction · 0.45
sendResultFunction · 0.45
streamWriteFunction · 0.45
streamWriteFunction · 0.45
streamWriteFunction · 0.45
sendFunction · 0.45
WriteHTTPHeadersFunction · 0.45

Calls 5

corkMethod · 0.80
uncorkMethod · 0.80
onBodySentMethod · 0.65
toStringMethod · 0.45
refreshMethod · 0.45

Tested by

no test coverage detected