git ssb

2+

Dominic / pull-stream



Tree: 0990f2724d1de3b5d3ac4000a6cb2680aab8c194

Files: 0990f2724d1de3b5d3ac4000a6cb2680aab8c194 / index.js

1652 bytesRaw
1var sources = require('./sources')
2var sinks = require('./sinks')
3var throughs = require('./throughs')
4var u = require('pull-core')
5
6function isFunction (fun) {
7 return 'function' === typeof fun
8}
9
10function isReader (fun) {
11 return fun && (fun.type === "Through" || fun.length === 1)
12}
13var exports = module.exports = function pull () {
14 var args = [].slice.call(arguments)
15
16 if(isReader(args[0]))
17 return function (read) {
18 args.unshift(read)
19 return pull.apply(null, args)
20 }
21
22 var read = args.shift()
23
24 //if the first function is a duplex stream,
25 //pipe from the source.
26 if(isFunction(read.source))
27 read = read.source
28
29 function next () {
30 if(!args.length) return read
31 var s = args.shift()
32
33 if(null == s)
34 return next()
35
36 if(isFunction(s)) return s
37
38 return function (read) {
39 s.sink(read)
40 //this supports pipeing through a duplex stream
41 //pull(a, b, a) "telephone style".
42 //if this stream is in the a (first & last position)
43 //s.source will have already been used, but this should never be called
44 //so that is okay.
45 return s.source
46 }
47 }
48
49 while(args.length)
50 read = next() (read)
51
52 return read
53}
54
55
56for(var k in sources)
57 exports[k] = u.Source(sources[k])
58
59for(var k in throughs)
60 exports[k] = u.Through(throughs[k])
61
62for(var k in sinks)
63 exports[k] = u.Sink(sinks[k])
64
65var maybe = require('./maybe')(exports)
66
67for(var k in maybe)
68 exports[k] = maybe[k]
69
70exports.Duplex =
71exports.Through = exports.pipeable = u.Through
72exports.Source = exports.pipeableSource = u.Source
73exports.Sink = exports.pipeableSink = u.Sink
74
75
76

Built with git-ssb-web