Slide 70
Slide 70 text
Stream Pipeline API
const { pipeline, Transform } = require('stream');
const rs = fs.createReadStream('./stream.js');
const ts = new Transform({
transform(chunk, encoding, callback) {
callback(null, chunk.toString().toUpperCase())
}
});
const ws = fs.createWriteStream('./stream_cap.js');
pipeline(rs, ts, ws, (err) => {
if (err) {
console.error(err);
return;
}
console.log('Stream is done reading');
});
rs.resume();