0

I have an object in node that has .stdin, .stderr and .stdout objects attached to it. I have stdout and stderr working as Writable streams and I'm having some trouble getting stdin to work as a Readable stream.

In the use case I'm building for I could do the following:

var stream = require('stream');
var util = require('util');
var Readable = stream.Readable;
var My_Stdin = function(){
    Readable.call(this, {objectMode: true});
};
util.inherits(My_Stdin, Readable);
My_Stdin.prototype._read = function(data) {
    this.emit(data);
};

function myObject(){
    this.stdin = new My_Stdin;

    this.stdin.on('data', function(data){
        process.stdout.write(data);
    });
}

var object = new myObject;
process.stdin.pipe(object.stdin);

Right now I'm getting an error that says:

_stream_readable.js:525

var ret = dest.write(chunk); ^

TypeError: dest.write is not a function

How do I properly implement a stdin on my object similar to child_process.spawn?

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
Eric Uldall
  • 2,282
  • 1
  • 17
  • 30

0 Answers0