Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Feature request: splitArray #104

Open
Vanuan opened this issue May 28, 2017 · 0 comments
Open

Feature request: splitArray #104

Vanuan opened this issue May 28, 2017 · 0 comments

Comments

@Vanuan
Copy link

Vanuan commented May 28, 2017

It's kind of tricky to find out how to use "through". It would be easier if there was a dedicated splitArray() function:

function splitArray() {
  return es.through(function emitArray(array) {
    array.forEach(function(item) {
      this.emit('data', item);
    }.bind(this));
  }, function end() {
    this.emit('end');
  })
}

// input example:

[{value1: 1},{value2: 2},{value3: 3}]
[{value4: 4},{value5: 5},{value6: 6}]
[{value7: 7},{value8: 8},{value9: 9}]

// usage:

inputStream
  .pipe(es.split())
  .pipe(es.map((line, callback) => { line ? callback(null, line) : callback() }))
  .pipe(es.parse())
  .pipe(es.splitArray())
  .pipe(es.map(function (data, cb) {
    cb(null
      , inspect(JSON.parse(data)))
  }))
  .pipe(process.stdout);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants
@Vanuan and others