git ssb

2+

Dominic / pull-stream



Tree: f067dd3a7d3bae43354dc23037f538568ce040ad

Files: f067dd3a7d3bae43354dc23037f538568ce040ad / sinks.js

844 bytesRaw
1var drain = exports.drain = function (read, op, done) {
2
3 ;(function next() {
4 var loop = true, cbed = false
5 while(loop) {
6 cbed = false
7 read(null, function (end, data) {
8 cbed = true
9 if(end) {
10 loop = false
11 if(done) done(end === true ? null : end)
12 else if(end && end !== true)
13 throw end
14 }
15 else if(op && false === op(data)) {
16 loop = false
17 read(true, done || function () {})
18 }
19 else if(!loop){
20 next()
21 }
22 })
23 if(!cbed) {
24 loop = false
25 return
26 }
27 }
28 })()
29}
30
31var onEnd = exports.onEnd = function (read, done) {
32 return drain(read, null, done)
33}
34
35var log = exports.log = function (read, done) {
36 return drain(read, function (data) {
37 console.log(data)
38 }, done)
39}
40
41

Built with git-ssb-web