Files: bb1bdb89523248804aace29fa3128944c6b432c3 / sinks.js
782 bytesRaw
1 | var 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 | done && done(end === true ? null : end) |
12 | } |
13 | else if(op && false === op(data)) { |
14 | loop = false |
15 | read(true, done || function () {}) |
16 | } |
17 | else if(!loop){ |
18 | next() |
19 | } |
20 | }) |
21 | if(!cbed) { |
22 | loop = false |
23 | return |
24 | } |
25 | } |
26 | })() |
27 | } |
28 | |
29 | var onEnd = exports.onEnd = function (read, done) { |
30 | return drain(read, null, done) |
31 | } |
32 | |
33 | var log = exports.log = function (read, done) { |
34 | return drain(read, function (data) { |
35 | console.log(data) |
36 | }, done) |
37 | } |
38 | |
39 |
Built with git-ssb-web