6

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)?

krl
  • 5,087
  • 4
  • 36
  • 53

1 Answers1

1

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
robertklep
  • 198,204
  • 35
  • 394
  • 381
  • 2
    BEWARE! This package has been archived (possibly not maintained any more) and has a serious security risk as per https://github.com/dominictarr/event-stream/issues/115 – cortopy Jul 17 '19 at 13:22