Files: 545734ec6384c1b2b71f539ea4acfe56af123b1e / sinks.js
885 bytesRaw
1 | |
2 | var reduce = exports.reduce = |
3 | function (read, reduce, acc, cb) { |
4 | read(null, function next (end, data) { |
5 | if(end) return cb(end === true ? null : end, acc) |
6 | acc = reduce(acc, data) |
7 | read(null, next) |
8 | }) |
9 | } |
10 | |
11 | var collect = exports.collect = exports.writeArray = |
12 | function (read, cb) { |
13 | return reduce(read, function (arr, item) { |
14 | arr.push(item) |
15 | return arr |
16 | }, [], cb) |
17 | } |
18 | |
19 | |
20 | var onEnd = exports.onEnd = function (read, done) { |
21 | return read(null, function next (err, data) { |
22 | if(err) return done(err === true ? null : err) |
23 | read(null, next) |
24 | }) |
25 | } |
26 | |
27 | var drain = exports.drain = function (read, op, done) { |
28 | return read(null, function next (err, data) { |
29 | if(err) return done && done(err === true ? null : err) |
30 | op && op(data) |
31 | read(null, next) |
32 | }) |
33 | } |
34 | |
35 | var log = exports.log = function (read, done) { |
36 | return drain(read, console.log.bind(console), done) |
37 | } |
38 | |
39 |
Built with git-ssb-web