Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
JavaScript
branch: master

Merge pull request #1 from timoxley/patch-1

typo: missing end of code block
latest commit 0e56559a79
@dominictarr authored
Failed to load latest commit information.
test tidy
.gitignore initial
.travis.yml initial
LICENSE initial
README.md typo: missing end of code block
index.js initial
package.json fix test script

README.md

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 = require('invert-stream')

var inverted = invert()

in_steam.pipe(inverted.other).pipe(out_stream)

inverted.write(data_for_outstream)
inverted.on('data', data_from_in_stream)

why ?

this is useful for a couple of things.

  • testing streams based stuff
  • making flexible duplex stream apis

an invert-stream pair is like a tcp connection, but in-process and synchronous. It's way easier to test edge cases related to event order if you stuff works sync.

Also, it's useful making duplex streams, or multiple streams into one.

Example

  var spawn = require('child_process').spawn
  var 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 stdin
  inverted.write(data)

  //read from ch's stdout
  inverted.on('data', ...) 

License

MIT

Something went wrong with that request. Please try again.