invert-stream
Create a pair of streams (A, B) such that A.write(X) -> B.emit('data', X)
and B.write(X) -> A.emit('data', X)
var invert =var inverted =in_steaminvertedinverted## why ?this is useful for a couple of things* testing streams based stuff* making flexible duplex stream apisan `invert-stream` pair is like a tcp connectionbut in-process and synchronous It's way easier to testedge cases related to event order if you stuff works sync.Also, it's useful making duplex streams or multiple streams into one### Example```jsvar spawn = require('child_process').spawnvar invert = require('invert-stream')var ch = spawn(cmd, args)var inverted = invert()ch.stdout.pipe(inverted.other).pipe(ch.sdin)//now, we have just ONE stream: inverted//write to che ch's stdininverted.write(data)//read from ch's stdoutinverted.on('data', ...)
License
MIT