Skip to content

Is there a way to insert data? #162

Closed Answered by uhop
sanjacob asked this question in Q&A
Discussion options

You must be logged in to vote

Just use stream-chain, which is the only dependency of stream-json (a sketch):

const {chain} = require('stream-chain');

const pipeline = chain([
  fs.createReadStream('data.json.gz'),
  zlib.createGunzip(),
  parser(),
  streamArray(),
  function* ({key, value}) {
    if (key % 2 == 1) yield 123;
    yield 'qwerty';
    yield {key, value: value + 42};
   // and so on
  }
]);

Imagination is the only limit.

Two notes:

  • Do not pass down the pipe naked falsy values. Just in case. I usually wrap them like that: [null] or {value: null}.
  • stream-chain used by this package is 2.x (no need to import it explicitly). The newly released version of stream-chain is 3.x. Its wiki clearly separates 2.x f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@sanjacob
Comment options

Answer selected by sanjacob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
2 participants