Simple example of how stream transforms work
const { createReadStream, createWriteStream } = require('fs') | |
const { Transform } = require('stream') | |
const stream = createReadStream('./text.txt') | |
const writeStream = createWriteStream('./result.txt') | |
const transformStream = new Transform({ | |
transform (chunk, encoding, done) { | |
let text = String(chunk) | |
text = text.toLowerCase().replace(/hola/g, 'adiós') | |
done(null, text) | |
} | |
}) | |
async function start () { | |
stream | |
.pipe(transformStream) | |
.pipe(writeStream) | |
} | |
start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment