Combining multiple streams
This code demonstrates how to combine a readable stream, a transform stream, and a writable stream using stream-combiner2. The readable stream generates data, the transform stream modifies the data, and the writable stream outputs the final result.
const combine = require('stream-combiner2');
const { Readable, Transform, Writable } = require('stream');
const readable = new Readable({
read() {
this.push('data');
this.push(null);
}
});
const transform = new Transform({
transform(chunk, encoding, callback) {
this.push(chunk.toString().toUpperCase());
callback();
}
});
const writable = new Writable({
write(chunk, encoding, callback) {
console.log(chunk.toString());
callback();
}
});
const combinedStream = combine(readable, transform, writable);
combinedStream.on('finish', () => console.log('Stream processing completed.'));