-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
30 lines (23 loc) · 855 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var through2 = require('through2')
var bun = require('bun')
// syntactic sugar for wrapping a duplex stream with two transforms.
module.exports = duplexTransform
function duplexTransform(outgoing, stream, incoming) {
if (typeof(outgoing) === 'function')
outgoing = through2(outgoing)
if (typeof(incoming) === 'function')
incoming = through2(incoming)
var wrapped = bun([outgoing, stream, incoming])
wrapped.outgoing = outgoing
wrapped.middle = stream
wrapped.incoming = incoming
return wrapped
}
// sugar for not having to include through2 just for `.obj`
duplexTransform.obj = function(outgoing, stream, incoming) {
if (typeof(outgoing) === 'function')
outgoing = through2.obj(outgoing)
if (typeof(incoming) === 'function')
incoming = through2.obj(incoming)
return duplexTransform(outgoing, stream, incoming)
}