streamToBytes
streamToBytes(
stream):Promise<Uint8Array<ArrayBufferLike>>
Defined in: common.ts:94
Convert a byte stream to a single Uint8Array.
Reads all chunks from the stream and concatenates them. Unlike Node’s
Buffer.concat, this works in every runtime that has ReadableStream —
browsers included.
A single-chunk stream returns that chunk as-is rather than a copy. Web Streams transfer chunk ownership to the reader, so this is safe, but it does mean the result may be a view over a larger buffer. Copy it before mutating if the origin of the stream is unknown.
Parameters
Section titled “Parameters”stream
Section titled “stream”ReadableStream<Uint8Array<ArrayBufferLike>>
The byte stream to read
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBufferLike>>
Promise resolving to the concatenated bytes
Example
Section titled “Example”const stream = await ctx.readFile('report.xlsx')const bytes = await streamToBytes(stream)