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(
await (async () => {
let count = 0;
await pipeline(
Readable.from(["a", "b"]),
new Writable({
write(c, e, done) {
count += c.length;
done();
},
}),
);
return count;
})(),
);
Sample output
2
