MCPcopy Create free account
hub / github.com/angular/dev-infra / writeStream

Function writeStream

github-actions/saucelabs/set-saucelabs-env.js:6757–6826  ·  view source on GitHub ↗
(abort, body, client, request, socket, contentLength, header, expectsPayload)

Source from the content-addressed store, hash-verified

6755 writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload);
6756 } else if (util.isBuffer(body)) {
6757 writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload);
6758 } else if (util.isBlobLike(body)) {
6759 if (typeof body.stream === "function") {
6760 writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload);
6761 } else {
6762 writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload);
6763 }
6764 } else if (util.isStream(body)) {
6765 writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload);
6766 } else if (util.isIterable(body)) {
6767 writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload);
6768 } else {
6769 assert(false);
6770 }
6771 return true;
6772 }
6773 function writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload) {
6774 var _a, _b, _c;
6775 assert(contentLength !== 0 || client[kRunning] === 0, "stream body cannot be pipelined");
6776 let finished = false;
6777 const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header });
6778 const onData = function(chunk) {
6779 if (finished) {
6780 return;
6781 }
6782 try {
6783 if (!writer.write(chunk) && this.pause) {
6784 this.pause();
6785 }
6786 } catch (err) {
6787 util.destroy(this, err);
6788 }
6789 };
6790 const onDrain = function() {
6791 if (finished) {
6792 return;
6793 }
6794 if (body.resume) {
6795 body.resume();
6796 }
6797 };
6798 const onClose = function() {
6799 queueMicrotask(() => {
6800 body.removeListener("error", onFinished);
6801 });
6802 if (!finished) {
6803 const err = new RequestAbortedError();
6804 queueMicrotask(() => onFinished(err));
6805 }
6806 };
6807 const onFinished = function(err) {
6808 if (finished) {
6809 return;
6810 }
6811 finished = true;
6812 assert(socket.destroyed || socket[kWriting] && client[kRunning] <= 1);
6813 socket.off("drain", onDrain).off("error", onFinished);
6814 body.removeListener("data", onData).removeListener("end", onFinished).removeListener("close", onClose);

Callers 2

writeH1Function · 0.70
writeBodyH2Function · 0.70

Calls 8

onFinishedFunction · 0.70
pipelineFunction · 0.70
abortFunction · 0.70
onMethod · 0.45
resumeMethod · 0.45
destroyMethod · 0.45
onRequestSentMethod · 0.45
addListenerMethod · 0.45

Tested by

no test coverage detected