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zB,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { getRawContent } from \"./file.js\";\nimport { isNodeReadableStream, isWebReadableStream } from \"./typeGuards.js\";\n\n/**\n * Drain the content of the given ReadableStream into a Blob.\n * The blob's content may end up in memory or on disk dependent on size.\n */\nfunction drain(stream: ReadableStream): Promise {\n return new Response(stream).blob();\n}\n\nasync function toBlobPart(\n source: ReadableStream | Blob | Uint8Array,\n): Promise {\n if (source instanceof Blob || source instanceof Uint8Array) {\n return source;\n }\n\n if (isWebReadableStream(source)) {\n return drain(source);\n }\n\n // If it's not a true Blob, and it's not a Uint8Array, we can assume the source\n // is a fake File created by createFileFromStream and we can get the original stream\n // using getRawContent.\n const rawContent = getRawContent(source);\n\n // Shouldn't happen but guard for it anyway\n if (isNodeReadableStream(rawContent)) {\n throw new Error(\n \"Encountered unexpected type. In the browser, `concat` supports Web ReadableStream, Blob, Uint8Array, and files created using `createFile` only.\",\n );\n }\n\n return toBlobPart(rawContent);\n}\n\n/**\n * Accepted binary data types for concat\n *\n * @internal\n */\ntype ConcatSource = ReadableStream | Blob | Uint8Array;\n\n/**\n * Utility function that concatenates a set of binary inputs into one combined output.\n *\n * @param sources - array of sources for the concatenation\n * @returns - in Node, a (() =\\> NodeJS.ReadableStream) which, when read, produces a concatenation of all the inputs.\n * In browser, returns a `Blob` representing all the concatenated inputs.\n *\n * @internal\n */\nexport async function concat(\n sources: (ConcatSource | (() => ConcatSource))[],\n): Promise<(() => NodeJS.ReadableStream) | Blob> {\n const parts = [];\n for (const source of sources) {\n parts.push(await toBlobPart(typeof source === \"function\" ? source() : source));\n }\n\n return new Blob(parts);\n}\n"]}