pull-stream
Advanced tools
Comparing version 2.10.1 to 2.10.2
{ | ||
"name": "pull-stream", | ||
"description": "minimal pull stream", | ||
"version": "2.10.1", | ||
"version": "2.10.2", | ||
"homepage": "https://github.com/dominictarr/pull-stream", | ||
@@ -6,0 +6,0 @@ "repository": { |
43
sinks.js
@@ -0,8 +1,30 @@ | ||
var drain = exports.drain = function (read, op, done) { | ||
;(function next() { | ||
var sync = true, returned = false, loop = true | ||
do { | ||
returned = false; sync = true | ||
read(null, function (err, data) { | ||
returned = true | ||
if(err) { | ||
done && done(err === true ? null : err) | ||
return loop = false | ||
} | ||
op && op(data) | ||
if(!sync) next() | ||
}) | ||
sync = false | ||
if(!returned) return | ||
} while (loop); | ||
})() | ||
} | ||
var reduce = exports.reduce = | ||
function (read, reduce, acc, cb) { | ||
read(null, function next (end, data) { | ||
if(end) return cb(end === true ? null : end, acc) | ||
drain(read, function (data) { | ||
acc = reduce(acc, data) | ||
read(null, next) | ||
}, function (err) { | ||
cb(err, acc) | ||
}) | ||
@@ -19,18 +41,9 @@ } | ||
//if the source callsback sync, then loop | ||
//rather than recurse | ||
var onEnd = exports.onEnd = function (read, done) { | ||
return read(null, function next (err, data) { | ||
if(err) return done(err === true ? null : err) | ||
read(null, next) | ||
}) | ||
return drain(read, null, done) | ||
} | ||
var drain = exports.drain = function (read, op, done) { | ||
return read(null, function next (err, data) { | ||
if(err) return done && done(err === true ? null : err) | ||
op && op(data) | ||
read(null, next) | ||
}) | ||
} | ||
var log = exports.log = function (read, done) { | ||
@@ -37,0 +50,0 @@ return drain(read, console.log.bind(console), done) |
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
30714
775