Skip to content

Commit

Permalink
added child_process device
Browse files Browse the repository at this point in the history
  • Loading branch information
bjouhier committed Sep 9, 2014
1 parent 4e6043f commit 28b9d1f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions lib/devices/child_process._js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";

var node = require('./node');

module.exports = {
/// !doc
/// ## EZ Stream wrappers for node child processes
///
/// `var ez = require('ez-streams');`
///
/// * `reader = ez.devices.child_process.reader(proc, options)`
/// wraps a node.js child process as an EZ reader.
/// For a full description of the options, see `ReadableStream` in
/// https://github.com/Sage/streamline-streams/blob/master/lib/streams.md
reader: function(proc, options) {
var stdout = node.reader(proc.stdout, options);
var stderr = node.reader(proc.stderr, options);
if (options.dataHandler) stdout = options.dataHandler(stdout);
if (options.errorHandler) stderr = options.errorHandler(stderr);
if (options.errorPrefix || options.errorThrow) stderr = stderr.map(function(_, data) {
if (options.errorThrow) throw new Error((options.errorPrefix || "") + data);
return options.errorPrefix + data;
});
return stdout.join(stderr);
},
/// * `writer = ez.devices.child_process.writer(proc, options)`
/// wraps a node.js child process as an EZ writer.
/// For a full description of the options, see `WritableStream` in
/// https://github.com/Sage/streamline-streams/blob/master/lib/streams.md
writer: function(proc, options) {
return node.writer(proc.stdin, options);
},
};
12 changes: 12 additions & 0 deletions lib/devices/child_process.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## EZ Stream wrappers for node child processes

`var ez = require('ez-streams');`

* `reader = ez.devices.child_process.reader(proc, options)`
wraps a node.js child process as an EZ reader.
For a full description of the options, see `ReadableStream` in
https://github.com/Sage/streamline-streams/blob/master/lib/streams.md
* `writer = ez.devices.child_process.writer(proc, options)`
wraps a node.js child process as an EZ writer.
For a full description of the options, see `WritableStream` in
https://github.com/Sage/streamline-streams/blob/master/lib/streams.md

0 comments on commit 28b9d1f

Please sign in to comment.