Skip to content

Commit

Permalink
buffer example
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Mar 21, 2013
1 parent ccff88b commit 6f854b5
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions README.md
Expand Up @@ -71,6 +71,37 @@ squares(function print(chunk, recurse) {
})
```

## Example buffers

```js
var Stream = require("stream")
var readstream = require("recurse-stream")
var buffer = require("recurse-stream/buffer")

var source = Stream()
// Wrapping a readable stream with `buffer` will correctly respect the
// writable's pulling requests and buffer up any chunks that come too fast
var stream = buffer(function (writable) {
source.on("data", function (chunk) {
writable(chunk, function () {})
})
})

// the chunks will print once per second
stream(function writeChunk(chunk, recurse) {
console.log("print chunk", chunk)

setTimeout(recurse, 1000)
})

source.emit("data", 1)
source.emit("data", 2)
source.emit("data", 3)
source.emit("data", 4)
source.emit("data", 5)
source.emit("data", null)
```

## Installation

`npm install recurse-stream`
Expand Down

0 comments on commit 6f854b5

Please sign in to comment.