Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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 () {
Hola don pepito
Hola don jose
Pasó usted por casa?
Por su casa yo pasé
Vió usted a mi abuela?
A su abuela yo la vi
Adiós don Pepito
Adiós don José
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment