Files: c35743ecbec8f9c5790187a9d319e9e2ef622684 / index.js
385 bytesRaw
1 | module.exports = function (read, onEnd) { |
2 | var vals = [] |
3 | |
4 | read(null, function next(end, data) { |
5 | if (end) return onEnd && onEnd(end === true ? null : end) |
6 | vals.push(data) |
7 | read(null, next) |
8 | }) |
9 | |
10 | return function () { |
11 | var i = vals.length - 1 |
12 | return function (end, cb) { |
13 | if (end) cb() |
14 | else if (i < 0) cb(true) |
15 | else cb(null, vals[i--]) |
16 | } |
17 | } |
18 | } |
19 |
Built with git-ssb-web