• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# stream-each
2
3Iterate all the data in a stream
4
5```
6npm install stream-each
7```
8
9[![build status](http://img.shields.io/travis/mafintosh/stream-each.svg?style=flat)](http://travis-ci.org/mafintosh/stream-each)
10
11## Usage
12
13``` js
14var each = require('stream-each')
15
16each(stream, function (data, next) {
17  console.log('data from stream', data)
18  // when ready to consume next chunk
19  next()
20}, function (err) {
21  console.log('no more data')
22})
23```
24
25## API
26
27#### `each(stream, iterator, cb)`
28
29Iterate the data in the stream by calling the iterator function with `(data, next)`
30where data is a data chunk and next is a callback. Call next when you are ready to
31consume the next chunk. Optionally you can call next with an error to destroy the stream
32
33When the stream ends/errors the callback is called if provided
34
35## License
36
37MIT
38
39## Related
40
41`stream-each` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
42