8000 Feature request: splitArray · Issue #104 · dominictarr/event-stream · GitHub
[go: up one dir, main page]

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

Open

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0