项目作者: manishrc

项目描述 :
CLI wrapper for node scripts to work with Unix pipes and streams.
高级语言: JavaScript
项目地址: git://github.com/manishrc/streaming-bird.git
创建时间: 2019-09-25T23:09:31Z
项目社区:https://github.com/manishrc/streaming-bird

开源协议:

下载


🐧 streaming-bird

CLI wrapper for node scripts to work with Unix pipes and streams.

Install

  1. $ npm install --global streaming-bird

Usage

  1. $ streaming-bird --help
  2. Usage
  3. $ streaming-bird [-i <file>] [-o <file>] <nodejs-script> ...
  4. Options
  5. -i, --input Read from a <file>
  6. -o, --output Write output to <file>
  7. -l, --lines Line mode ON (DEFAULT)
  8. --no-lines Disable line mode
  9. --json Parse JSON
  10. Examples
  11. $ streaming-bird -i huge-file.jsonl -o output.jsonl transformer-a.js
  12. $ cat huge-file.jsonl | streaming-bird transformer.js > output.jsonl

Examples

example-input.jsonl

  1. {"name": "Nickolas Swaniawski"}
  2. {"name": "Drake Bednar"}
  3. {"name": "Abbie Runte"}
  4. {"name": "Jessica Schmeler"}
  5. {"name": "Pearl Fay"}
  6. {"name": "Everett Shanahan"}

example-transformer-upcase.js

  1. module.exports = ({ name }) => {
  2. return { name: name.toUpperCase() };
  3. };

example-transformer-length.js

  1. module.exports = ({ name }) => {
  2. return { name, length: name.length };
  3. };

CLI

  1. $ cat example-input.jsonl \
  2. | streaming-bird -j example-transformer-upcase.js example-transformer-length.js \
  3. | sort > out.jsonl

Or

  1. $ streaming-bird -j example-transformer-upcase.js example-transformer-length.js \
  2. -i example-input.jsonl \
  3. -o out.jsonl

out.jsonl

  1. {"name":"ABBIE RUNTE","length":11}
  2. {"name":"DRAKE BEDNAR","length":12}
  3. {"name":"EVERETT SHANAHAN","length":16}
  4. {"name":"JESSICA SCHMELER","length":16}
  5. {"name":"NICKOLAS SWANIAWSKI","length":19}
  6. {"name":"PEARL FAY","length":9}

NOTE
The scripts are piped left-to-right. The result of the first script is passed on as the input of the second without serializing.

To work with serialized objects, parsing needs to happen only in the first script.

The result of the last script is serealized.