l0bsterssg

node.js static responsive blog post generator
Log | Files | Refs | README

readme.markdown (872B)


      1 [![TravisCI Build Status](https://travis-ci.org/nmhnmh/from.svg?branch=master)](https://travis-ci.org/nmhnmh/from)
      2 
      3 # from
      4 
      5 An easy way to create a `readable Stream`.
      6 
      7 ## from(function getChunk(count, next))
      8 
      9 from takes a `getChunk` function and returns a stream.  
     10 
     11 `getChunk` is called again and again, after each time the user calls `next()`, 
     12 until the user emits `'end'`
     13 
     14 if `pause()` is called, the `getChunk` won't be called again untill `resume()` is called.
     15 
     16 
     17 ```js
     18 var from = require('from')
     19 
     20 var stream = 
     21   from(function getChunk(count, next) {
     22     //do some sort of data
     23     this.emit('data', whatever)
     24     
     25     if(itsOver)
     26       this.emit('end')
     27 
     28     //ready to handle the next chunk
     29     next()
     30     //or, if it's sync:
     31     return true 
     32   })
     33 ```
     34 
     35 ## from(array)
     36 
     37 from also takes an `Array` whose elements it emits one after another.
     38 
     39 ## License
     40 MIT / Apache2