Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Replace map-stream with regular TransformStream
Browse files Browse the repository at this point in the history
Reverts #11. According to #15 the returned map-stream doesn't implement the expected
Readable interface, thus we're switching back to node's TransformStream.

Fixes #15
  • Loading branch information
jhnns committed Sep 3, 2014
1 parent dbc832d commit 76dc076
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
45 changes: 40 additions & 5 deletions lib/forkStdout.js
Original file line number Diff line number Diff line change
@@ -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: ";

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 76dc076

Please sign in to comment.