-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
226f7c6
commit c64037e
Showing
1 changed file
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
[![Build Status](https://travis-ci.org/bigeasy/staccato.svg?branch=master)](https://travis-ci.org/bigeasy/staccato) [![Coverage Status](https://coveralls.io/repos/bigeasy/staccato/badge.svg?branch=master&service=github)](https://coveralls.io/github/bigeasy/staccato?branch=master) | ||
|
||
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](https://github.com/bigeasy/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. | ||
|
||
|
||
```javascript | ||
var Staccato = require('staccato') | ||
var out = new Staccato(fs.createWriteStream('./out.txt')) | ||
|
||
var writer = cadence(function (async, bytes) { | ||
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 }) | ||
``` |