{"version":3,"file":"readBytesFromStream.mjs","names":[],"sources":["../../src/tools/readBytesFromStream.ts"],"sourcesContent":["import type { Uint8ArrayBuffer } from './utils/byteUtils'\nimport { concatBuffers } from './utils/byteUtils'\nimport { noop } from './utils/functionUtils'\n\n/**\n * Read bytes from a ReadableStream until the end of the stream.\n */\nexport async function readBytesFromStream(stream: ReadableStream<Uint8ArrayBuffer>) {\n  const reader = stream.getReader()\n  const chunks: Uint8ArrayBuffer[] = []\n\n  while (true) {\n    const result = await reader.read()\n    if (result.done) {\n      break\n    }\n\n    chunks.push(result.value)\n  }\n\n  reader.cancel().catch(\n    // we don't care if cancel fails, but we still need to catch the error to avoid reporting it\n    // as an unhandled rejection\n    noop\n  )\n\n  return concatBuffers(chunks)\n}\n"],"mappings":";;;;;;AAOA,eAAsB,oBAAoB,QAA0C;CAClF,MAAM,SAAS,OAAO,UAAU;CAChC,MAAM,SAA6B,CAAC;CAEpC,OAAO,MAAM;EACX,MAAM,SAAS,MAAM,OAAO,KAAK;EACjC,IAAI,OAAO,MACT;EAGF,OAAO,KAAK,OAAO,KAAK;CAC1B;CAEA,OAAO,OAAO,CAAC,CAAC,MAGd,IACF;CAEA,OAAO,cAAc,MAAM;AAC7B"}