New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: splitArray #104

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

Comments

Projects
None yet
2 participants
@Vanuan

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 join this conversation on GitHub. Already have an account? Sign in to comment