For when you want to wrap a stream in a buffer.
The buffer is a duplex stream which will emit data it got from the target and will write it any data written to it to the target once you empty the buffer.
It will buffer everything if you call buffer.
It's expected the target is a duplex stream.
var BufferStream = require("buffer-stream")
var target = SomeStream()
, buffer = BufferStream(target).buffer()
target.on("connect", function () {
// Ok we are ready to go!
buffer.empty()
})
target.on("disconnect", function () {
// Oops, better buffer again
buffer.buffer()
})
buffer.on("data", function (data) {
// We get this data once the buffer is emptied
// Any data emitted by the target before the empty call is buffered
})
// Will write to the target once the buffer is emptied
buffer.write("will be written once some-condition is met")