| language: node_js | ||
| node_js: | ||
| - 0.6 | ||
| - 0.8 |
+1
-62
| var Stream = require('stream') | ||
| // through | ||
@@ -10,4 +11,2 @@ // | ||
| exports.from = from | ||
| //create a readable writable stream. | ||
@@ -83,61 +82,1 @@ | ||
| //create a readable stream. | ||
| function from (source) { | ||
| if(Array.isArray(source)) | ||
| return from (function (i) { | ||
| if(source.length) | ||
| this.emit('data', source.shift()) | ||
| else | ||
| this.emit('end') | ||
| return true | ||
| }) | ||
| var s = new Stream(), i = 0, ended = false, started = false | ||
| s.readable = true | ||
| s.writable = false | ||
| s.paused = false | ||
| s.pause = function () { | ||
| started = true | ||
| s.paused = true | ||
| } | ||
| function next () { | ||
| var n = 0, r = false | ||
| if(ended) return | ||
| while(!ended && !s.paused && source.call(s, i, function () { | ||
| if(!n++ && !s.ended && !s.paused) | ||
| next() | ||
| })) | ||
| ; | ||
| } | ||
| s.resume = function () { | ||
| started = true | ||
| s.paused = false | ||
| next() | ||
| } | ||
| s.on('end', function () { | ||
| ended = true | ||
| s.readable = false | ||
| process.nextTick(s.destroy) | ||
| }) | ||
| s.destroy = function () { | ||
| ended = true | ||
| s.emit('close') | ||
| } | ||
| /* | ||
| by default, the stream will start emitting at nextTick | ||
| if you want, you can pause it, after pipeing. | ||
| you can also resume before next tick, and that will also | ||
| work. | ||
| */ | ||
| process.nextTick(function () { | ||
| if(!started) s.resume() | ||
| }) | ||
| return s | ||
| } | ||
| //create a writable stream. | ||
| function to () { | ||
| } |
+1
-1
| { | ||
| "name": "through", | ||
| "version": "0.0.2", | ||
| "version": "0.0.3", | ||
| "description": "simplified stream contruction", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
5
25%23
9.52%4792
-18.41%143
-28.14%