krl
krl

Reputation: 5296

Using Node.js readline in transform streams

We have a huge text file which we want to manipulate using stream line by line.

Is there a way to use Node.js readline module in a transform stream? For instance to make the whole text to use capital letter (processing it line by line)?

Upvotes: 7

Views: 2721

Answers (1)

robertklep
robertklep

Reputation: 203494

event-stream might be a better fit. It can split the input on lines and transform those lines in various ways (+ more).

For instance, to uppercase everything read from stdin:

const es = require('event-stream');

process.stdin
  .pipe(es.split())                              // split lines
  .pipe(es.mapSync(data => data.toUpperCase()))  // uppercase the line
  .pipe(es.join('\n'))                           // add a newline again
  .pipe(process.stdout);                         // write to stdout

Upvotes: 1

Related Questions