You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1012 B

4 years ago
  1. # stream-each
  2. Iterate all the data in a stream
  3. ```
  4. npm install stream-each
  5. ```
  6. [![build status](http://img.shields.io/travis/mafintosh/stream-each.svg?style=flat)](http://travis-ci.org/mafintosh/stream-each)
  7. ## Usage
  8. ``` js
  9. var each = require('stream-each')
  10. each(stream, function (data, next) {
  11. console.log('data from stream', data)
  12. // when ready to consume next chunk
  13. next()
  14. }, function (err) {
  15. console.log('no more data')
  16. })
  17. ```
  18. ## API
  19. #### `each(stream, iterator, cb)`
  20. Iterate the data in the stream by calling the iterator function with `(data, next)`
  21. where data is a data chunk and next is a callback. Call next when you are ready to
  22. consume the next chunk. Optionally you can call next with an error to destroy the stream
  23. When the stream ends/errors the callback is called if provided
  24. ## License
  25. MIT
  26. ## Related
  27. `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.