From what I understood about streams, Stream.Readable.pipe()
should pipe the data as soon as it receives it.
I am trying to implement my own streams but the output is not as expected.
const { Writable, Readable } = require("stream");
const writable = new Writable();
writable.data = [];
writable._write = (chunk, encoding, next) => {
writable.data.push(chunk.toString());
console.log(chunk.toString());
next();
};
const readable = new Readable({
read() {},
});
readable.pipe(writable);
readable.push("hi");
writable.write("ho");
writable.write("ho");
console.log(writable.data);
The output of this code is
ho
ho
[ 'ho', 'ho' ]
hi
The pipe is writing to the stream later. What does this mean?