git ssb

2+

Dominic / pull-stream



Tree: 9c7a2beba02414831d4a08c2de2021926e39c837

Files: 9c7a2beba02414831d4a08c2de2021926e39c837 / index.js

1619 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 var s = args.shift()
31
32 if(null == s)
33 return next()
34
35 if(isFunction(s)) return s
36
37 return function (read) {
38 s.sink(read)
39 //this supports pipeing through a duplex stream
40 //pull(a, b, a) "telephone style".
41 //if this stream is in the a (first & last position)
42 //s.source will have already been used, but this should never be called
43 //so that is okay.
44 return s.source
45 }
46 }
47
48 while(args.length)
49 read = next() (read)
50
51 return read
52}
53
54
55for(var k in sources)
56 exports[k] = u.Source(sources[k])
57
58for(var k in throughs)
59 exports[k] = u.Through(throughs[k])
60
61for(var k in sinks)
62 exports[k] = u.Sink(sinks[k])
63
64var maybe = require('./maybe')(exports)
65
66for(var k in maybe)
67 exports[k] = maybe[k]
68
69exports.Duplex =
70exports.Through = exports.pipeable = u.Through
71exports.Source = exports.pipeableSource = u.Source
72exports.Sink = exports.pipeableSink = u.Sink
73
74
75

Built with git-ssb-web