Comparing version 0.0.2 to 0.0.3
63
index.js
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 () { | ||
} |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5
23
4792
143