ES9 Async Iterables vs Transform Streams - Node

jfet97 / sbtts

something-better-than-transform-streams (Node v10 minimum)


something-better-than-transform-streams (Maybe) - Node v10 minimum

how to

1 Create a readable stream

const readableStream = ...

like for example:

const readableStream = require('fs').createReadStream('read.txt', {
        highWaterMark: 1024

2 Create a writable stream

const writableStream = ...

like for example:

const writableStream = require('fs').createWriteStream('write.txt');

3 Create one or more functions to modify each chunk asynchronously:

const toString = chunk => chunk.toString()
const toUpperCase = string => string.toUpperCase()
const crypt = uppercasedString => [...uppercasedString].reverse().join('');

4 Import my pipe function:

const { pipe } = require('./sbtts');

5 Use it:

// pipe(inputStream, outupStream [, ...modifiers]);
await pipe(readableStream, writableStream, toString, toUpperCase, crypt);

6 It will resolve in the writableStream…

Did you find this post useful? Show some love!
Classic DEV Post from Oct 5

Title suggestions for a history of computer science mini web series?!


Andrea Simone Costa
I'm a frontend develover ❀️
Join ❀️

The heartbeat of the software industry.