diff --git a/lib/forkStdout.js b/lib/forkStdout.js index 8e7e3ef..331809c 100644 --- a/lib/forkStdout.js +++ b/lib/forkStdout.js @@ -1,9 +1,10 @@ "use strict"; var os = require("os"); +var util = require("util"); var ForkStream = require("fork-stream"); var Linerstream = require("linerstream"); -var mapStream = require("map-stream"); +var Transform = require("stream").Transform; var messageToNode = "message to node: "; @@ -36,13 +37,13 @@ function forkStdout(stdout) { .pipe(fork); // Removes the 'message to node: '-prefix from every chunk. - phridgeEndpoint = fork.a.pipe(mapStream(function(data, cb){ - cb(null, data.slice(messageToNode.length)); + phridgeEndpoint = fork.a.pipe(new CropPhridgePrefix({ + encoding: "utf8" })); // We need to restore EOL-character in stdout stream - cleanStdoutEndpoint = fork.b.pipe(mapStream(function(data, cb){ - cb(null, data + os.EOL); + cleanStdoutEndpoint = fork.b.pipe(new RestoreLineBreaks({ + encoding: "utf8" })); return { @@ -51,4 +52,38 @@ function forkStdout(stdout) { }; } +/** + * Appends an EOL-character to every chunk. + * + * @param options + * @constructor + * @private + */ +function RestoreLineBreaks(options) { + Transform.call(this, options); +} +util.inherits(RestoreLineBreaks, Transform); + +RestoreLineBreaks.prototype._transform = function (chunk, enc, cb) { + this.push(chunk + os.EOL); + cb(); +}; + +/** + * Removes the 'message to node: '-prefix from every chunk. + * + * @param options + * @constructor + * @private + */ +function CropPhridgePrefix(options) { + Transform.call(this, options); +} +util.inherits(CropPhridgePrefix, Transform); + +CropPhridgePrefix.prototype._transform = function (chunk, enc, cb) { + this.push(chunk.slice(messageToNode.length)); + cb(); +}; + module.exports = forkStdout; \ No newline at end of file diff --git a/package.json b/package.json index 65d0068..97a49a7 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "dependencies": { "fork-stream": "^0.0.4", "linerstream": "^0.1.4", - "map-stream": "^0.1.0", "phantomjs": "^1.9.7-15", "temp": "^0.8.0", "when": "^3.4.2"