something-better-than-transform-streams (Node v10 minimum)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


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 You could use it to close the output stream:

// pipe(inputStream, outupStream [, ...modifiers]);
const outputStream = await pipe(readableStream, writableStream, toString, toUpperCase, crypt);
outputStream.end(); // same as writableStream.end()


It seems a bit faster than transform streams and it is simpler. I've tested it against them using Benchmark.js. Obviously my API is not as powerful as transform streams, but it could become. (I'm a dreamer). With big files it seems you can gain more than 8/10 seconds. It seems. Test it! Let me now here: or here: