Files: cc048d2d98e1cd95038b14d5816dd19931a7b0fa / throughs / through.js
473 bytesRaw
1 | |
2 | |
3 | //a pass through stream that doesn't change the value. |
4 | module.exports = function through (op, onEnd) { |
5 | var a = false |
6 | |
7 | function once (abort) { |
8 | if(a || !onEnd) return |
9 | a = true |
10 | onEnd(abort === true ? null : abort) |
11 | } |
12 | |
13 | return function (read) { |
14 | return function (end, cb) { |
15 | if(end) once(end) |
16 | return read(end, function (end, data) { |
17 | if(!end) op && op(data) |
18 | else once(end) |
19 | cb(end, data) |
20 | }) |
21 | } |
22 | } |
23 | } |
24 |
Built with git-ssb-web