I'm trying to create a wrapper around child_process.spawn but I'm having trouble understanding streams2. i know how to do this with the "old" streams
suppose I have a function BlackBox with the external api that looks like this: (|s are pipes) inputStream | BlackBox | outputStream but as BlackBox is a wrapper for child_process.spawn, it'll look like this internally inputStream | BlackBox.Writable -> stdin -> stdout -> BlackBox.Readable | outputStream what I have so far is the following: var Duplex = require('stream').Duplex var spawn = require('child_process').spawn var util = require('util') util.inherits(BlackBox, Duplex) function BlackBox () { Duplex.call(this) // Example process this.proc = spawn('convert', ['-', ':-']) var that = this // .push(null) signifies the end of a stream? this.proc.stdout.on('end', function () { that.push(null) }) } BlackBox.prototype._write = function (chunk, encoding, callback) { return this.proc.stdin.write(chunk, encoding, callback) } BlackBox.prototype._read = function (size) { var that = this this.proc.stdout.on('readable', function () { var chunk = this.read(size) if (chunk === null) that.push('') else that.push(chunk) }) } My main questions are: 1. Am I doing this correctly? Streams as an emitter makes more sense to me (data and end events, pause and resume), but if this is all you have to do to create a readable and writable steam, then I understand streams2. 2. Am I handling all the backpressure correctly? 3. Am I handling the end event correclty? 4. How would I handle BlackBox.prototype.destroy()? -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.