node package manager

staccato

Write to a Node.js stream using the error-first callback style.

Write to a Node.js stream using the error-first callback style. Staccato is part of the Cadence Universe. With it you can feed a stream using error-first callbacks, a write to the stream will block if the stream is paused or if there is too much back-pressure, so you can generate a stream from a Cadence loop and the loop will pause when the stream is full.

var Staccato = require('staccato')
var out = new Staccato(fs.createWriteStream('./out.txt'))
 
var writer = cadence(function (asyncbytes) {
    var written = 0
    var loop = async(function () {
        crypto.randomBytes(1024, async())
    }, function (bytes) {
        written += bytes.length
        out.write(bytes, async())
    }, function () {
        if (written >= bytes) {
            return [ loop.break ]
        }
    })()
})
 
writer(function (error) { if (error) throw error })