Dev Helpers
← Back

Collect a binary stream

Collect a binary stream using Node.js.

Open this example in the interactive library

Source code

import {
  Readable,
  Writable,
  Transform,
  PassThrough,
  isReadable,
  isWritable,
} from "node:stream";
import { text, json, arrayBuffer } from "node:stream/consumers";
import { pipeline, finished } from "node:stream/promises";
console.log([
  ...new Uint8Array(await arrayBuffer(Readable.from([Buffer.from([1, 2])]))),
]);

Sample output

[ 1, 2 ]