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

Function writeStream

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

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