Files: 623e06d3e4aae1dfccc051e0b1a5fa1e9cc405e4 / sinks.js
844 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 | 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 | |
31 | var onEnd = exports.onEnd = function (read, done) { |
32 | return drain(read, null, done) |
33 | } |
34 | |
35 | var 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