I have a real mental blockage around this stuff. Partly because the docs could probably be a little better, partly because it's changed over the years, probably partly because I'm dumb. Whatever. I'm going to try and document how to do stuff I occasionally need to do, so I can refer to it next time.
x.pipe(y) === y; // true
x.on(someEvent, callback) === x; // true
const myTransform = new Transform({
transform(chunk, encoding, callback) {
callback(doSomethingWith(chunk));
}
});
fs.createReadStream('somefile.txt').pipe(myTransform);
Readable streams default to 'paused mode'. The data doesn't start flowing unless you
- add a 'data' event handler
- call
stream.resume()
- call
stream.pipe(writable)
More information here. God, what a mess.
TODO what are the available events, does closing z
in x.pipe(y).pipe(z)
close x
, etc