How do I create a transform stream, where the only change it will effect, is appending a string to the end of a the incoming readable stream.
For example, let's say input.txt contains abcdef.
fs.createReadStream('input.txt', {encoding: 'utf8'})
    .pipe(appendTransform)
    .pipe(fs.createWriteStream('output.txt', {encoding: 'utf8'}));
What can I use for appendTransform, such that output.txt contains abcdefghi.
Create a transform stream:
var Transform = require('stream').Transform;
var appendTransform = new Transform({
    transform(chunk, encoding, callback) {
        callback(null, chunk);
    },
    flush(callback) {
        this.push('ghi');
        callback();
    }
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With