Dev Helpers
← Back

Encode a stream of strings

Encode a stream of strings using Node.js.

Open this example in the interactive library

Source code

const source = () =>
  new ReadableStream({
    start(c) {
      c.enqueue("a");
      c.enqueue("b");
      c.close();
    },
  });
console.log(
  (await Array.fromAsync(source().pipeThrough(new TextEncoderStream()))).map(
    (b) => [...b],
  ),
);

Sample output

[ [ 97 ], [ 98 ] ]