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

Feature request: splitArray #104

@Vanuan

Description

@Vanuan

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions