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

Function extractBody

github-actions/browserstack/set-browserstack-env.js:5621–5769  ·  view source on GitHub ↗
(object, keepalive = false)

Source from the content-addressed store, hash-verified

5619 var streamRegistry;
5620 if (hasFinalizationRegistry) {
5621 streamRegistry = new FinalizationRegistry((weakRef) => {
5622 const stream = weakRef.deref();
5623 if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) {
5624 stream.cancel("Response object has been garbage collected").catch(noop);
5625 }
5626 });
5627 }
5628 function extractBody(object, keepalive = false) {
5629 let stream = null;
5630 if (object instanceof ReadableStream) {
5631 stream = object;
5632 } else if (isBlobLike(object)) {
5633 stream = object.stream();
5634 } else {
5635 let _a;
5636 stream = new ReadableStream({
5637 pull(controller) {
5638 return __async(this, null, function* () {
5639 const buffer = typeof source === "string" ? textEncoder.encode(source) : source;
5640 if (buffer.byteLength) {
5641 controller.enqueue(buffer);
5642 }
5643 queueMicrotask(() => readableStreamClose(controller));
5644 });
5645 },
5646 start() {
5647 },
5648 type: "bytes"
5649 });
5650 }
5651 assert(isReadableStreamLike(stream));
5652 let action = null;
5653 let source = null;
5654 let length = null;
5655 let type = null;
5656 if (typeof object === "string") {
5657 source = object;
5658 type = "text/plain;charset=UTF-8";
5659 } else if (object instanceof URLSearchParams) {
5660 source = object.toString();
5661 type = "application/x-www-form-urlencoded;charset=UTF-8";
5662 } else if (isArrayBuffer(object)) {
5663 source = new Uint8Array(object.slice());
5664 } else if (ArrayBuffer.isView(object)) {
5665 source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength));
5666 } else if (util.isFormDataLike(object)) {
5667 const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, "0")}`;
5668 const prefix = `--${boundary}\r
5669Content-Disposition: form-data`;
5670 const escape = (str) => str.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
5671 const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
5672 const blobParts = [];
5673 const rn = new Uint8Array([13, 10]);
5674 length = 0;
5675 let hasUnknownSizeValue = false;
5676 for (const [name, value] of object) {
5677 if (typeof value === "string") {
5678 const chunk2 = textEncoder.encode(prefix + `; name="${escape(normalizeLinefeeds(name))}"\r

Callers 7

safelyExtractBodyFunction · 0.70
writeH1Function · 0.70
writeH2Function · 0.70
jsonMethod · 0.70
constructorMethod · 0.70
constructorMethod · 0.70
schemeFetchFunction · 0.70

Calls 11

isBlobLikeFunction · 0.70
isReadableStreamLikeFunction · 0.70
escapeFunction · 0.70
normalizeLinefeedsFunction · 0.70
__asyncGeneratorFunction · 0.70
__yieldStarFunction · 0.70
ReadableStreamFromFunction · 0.70
streamMethod · 0.45
toStringMethod · 0.45
sliceMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected