UNPKG

473 BJavaScriptView Raw
1'use strict'
2
3//a pass through stream that doesn't change the value.
4module.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}