Hooking into Node.js writable stream
Based on this gist. Useful when you need to test Node writable streams such as stdout.
Install
$ npm install --save-dev hook-writable-stream
Usage
Use a callback
var hookWritableStream = ;var hook = ; console;hook;console;//=> 'unhooked!' is shown on your console
Use as a stream
var hookWritableStream = ;var through = ; var hook = ;var stream = hookstream;stream; console;hook;console;//=> 'unhooked!' is shown on your console
API
hookWritableStream(writableStream, [keepOriginal], [callback])
Returns an object.
unhook
Type: function
Call to unhook the writable stream.
stream
A stream that you can consume. The data that was going to written to the original stream is written to this stream.
writableStream
A node writable stream such as process.stdout
.
keepOriginal
true
to keep writing to the original stream.
callback(obj)
obj
Whatever is written to the original stream.
License
MIT © Steve Mao