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

Function writeStream

deps/undici/undici.js:7979–8047  ·  view source on GitHub ↗
(abort, body, client, request, socket, contentLength, header, expectsPayload)

Source from the content-addressed store, hash-verified

7977 }
7978 __name(writeH1, "writeH1");
7979 function writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload) {
7980 assert(contentLength !== 0 || client[kRunning] === 0, "stream body cannot be pipelined");
7981 let finished = false;
7982 const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header });
7983 const onData = /* @__PURE__ */ __name(function(chunk) {
7984 if (finished) {
7985 return;
7986 }
7987 try {
7988 if (!writer.write(chunk) && this.pause) {
7989 this.pause();
7990 }
7991 } catch (err) {
7992 util.destroy(this, err);
7993 }
7994 }, "onData");
7995 const onDrain = /* @__PURE__ */ __name(function() {
7996 if (finished) {
7997 return;
7998 }
7999 if (body.resume) {
8000 body.resume();
8001 }
8002 }, "onDrain");
8003 const onClose = /* @__PURE__ */ __name(function() {
8004 queueMicrotask(() => {
8005 body.removeListener("error", onFinished);
8006 });
8007 if (!finished) {
8008 const err = new RequestAbortedError();
8009 queueMicrotask(() => onFinished(err));
8010 }
8011 }, "onClose");
8012 const onFinished = /* @__PURE__ */ __name(function(err) {
8013 if (finished) {
8014 return;
8015 }
8016 finished = true;
8017 assert(socket.destroyed || socket[kWriting] && client[kRunning] <= 1);
8018 socket.off("drain", onDrain).off("error", onFinished);
8019 body.removeListener("data", onData).removeListener("end", onFinished).removeListener("close", onClose);
8020 if (!err) {
8021 try {
8022 writer.end();
8023 } catch (er) {
8024 err = er;
8025 }
8026 }
8027 writer.destroy(err);
8028 if (err && (err.code !== "UND_ERR_INFO" || err.message !== "reset")) {
8029 util.destroy(body, err);
8030 } else {
8031 util.destroy(body);
8032 }
8033 }, "onFinished");
8034 body.on("data", onData).on("end", onFinished).on("error", onFinished).on("close", onClose);
8035 if (body.resume) {
8036 body.resume();

Callers 2

writeH1Function · 0.70
writeBodyH2Function · 0.70

Calls 15

writeMethod · 0.95
endMethod · 0.95
destroyMethod · 0.95
__nameFunction · 0.85
queueMicrotaskFunction · 0.85
onFinishedFunction · 0.85
pipelineFunction · 0.70
abortFunction · 0.70
pauseMethod · 0.65
resumeMethod · 0.65
onRequestSentMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…