All files / util/src/streams fromStream.ts

100% Statements 11/11
100% Branches 1/1
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 131x   1x 2x 2x 2x 5x 5x 3x   2x    
import {listToUint8} from '@jsonjoy.com/buffers/lib/concat';
 
export const fromStream = async (stream: ReadableStream<Uint8Array>): Promise<Uint8Array> => {
  const reader = stream.getReader();
  const chunks: Uint8Array[] = [];
  while (true) {
    const {done, value} = await reader.read();
    if (done) break;
    chunks.push(value);
  }
  return listToUint8(chunks);
};