git ssb

2+

Dominic / pull-stream



Tree: 85d4b278b3e450513004c2f25cc0a16b2e512f7e

Files: 85d4b278b3e450513004c2f25cc0a16b2e512f7e / sinks.js

863 bytesRaw
1
2var reduce = exports.reduce =
3function (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
11var collect = exports.collect = exports.writeArray =
12function (read, cb) {
13 return reduce(read, function (arr, item) {
14 arr.push(item)
15 return arr
16 }, [], cb)
17}
18
19
20var 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
27var drain = exports.drain = function (read, op, done) {
28 return read(null, function next (err, data) {
29 if(err) return done && done(err)
30 op && op(data)
31 read(null, next)
32 })
33}
34
35var log = exports.log = function (read, done) {
36 return drain(read, console.log.bind(console), done)
37}
38
39

Built with git-ssb-web