bacon-spawn

0.1.0 • Public • Published

Build Status

Introduction

bacon-spawn - spawn child process and create bacon stream

Synopsis

var bacon_spawn = require('bacon-spawn'),
    Bacon = require('baconjs');
 
var bacon_stream = bacon_spawn(Bacon,'ls', ['-lh', './']);

Installation

If you have npm installed, you can simply type:

      npm install bacon-spawn

Or you can clone this repository using the git command:

      git clone git://github.com/JSBizon/bacon-spawn.git

Usage

Start child process and create Bacon stream:

var bacon_spawn = require('bacon-spawn'),
    Bacon = require('baconjs');
 
var bacon_stream = bacon_spawn(Bacon,'cat', ['./file.txt']);

bacon_stream will produce events objects.

{
    type: 'stdout',
    data: data,
    process: process,
    code: code,
    signal: signal
    sendHandle: sendHandle,
}

Event object properties:

  • type - string - the name of event, could be: 'stdout', 'stdin', 'close', 'exit', 'message', 'diconnect' produced by child process.
  • data - Buffer - piece of data for 'stdout', 'stdin' and 'message' events
  • process - ChildProcess - object of child processes
  • code - number - the exit code for 'close' and 'exit' events
  • signal - string - the signal passed to kill the child process
  • sendHandle - Handle object

You can connect bacon stream how stdin for child process:

    var stdin = BACON.sequentially(1,['value1','value2']);
    var stream = bacon_spawn(Bacon, 'cat').connect(stdin);

Examples

Read stdout:

    var stream = bacon_spawn(Bacon, 'cat', ['./file.txt']);
    stream2.filter(function(v) {
        return v.type === 'stdout' ? true : false;
    }).map(function (v) {
        return v.data ? v.data.toString() : '';
    }).reduce('', function (seed, ev) {
        return seed + ev;
    }).onValue(function(full_stdout) {
        console.log(full_stdout);
    })

Connect stdout from one process to stdin for other:

    var stdin = bacon_spawn(Bacon, 'ls', ['-lh', './']).filter(function (ev) {
        return ev.type === 'stdout' ? true : false;
    }).map(function(ev) {
        return ev.data.toString();
    });
 
    var stream = bacon_spawn(Bacon, 'cat').connect(stdin);

Package Sidebar

Install

npm i bacon-spawn

Weekly Downloads

2

Version

0.1.0

License

MIT

Last publish

Collaborators

  • jsbizon