Files: 66cac3c056c184eb58ccbdd628cb74b1917bb4ab / index.js
1619 bytesRaw
1 | var sources = require('./sources') |
2 | var sinks = require('./sinks') |
3 | var throughs = require('./throughs') |
4 | var u = require('pull-core') |
5 | |
6 | function isFunction (fun) { |
7 | return 'function' === typeof fun |
8 | } |
9 | |
10 | function isReader (fun) { |
11 | return fun && (fun.type === "Through" || fun.length === 1) |
12 | } |
13 | var 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 | |
55 | for(var k in sources) |
56 | exports[k] = u.Source(sources[k]) |
57 | |
58 | for(var k in throughs) |
59 | exports[k] = u.Through(throughs[k]) |
60 | |
61 | for(var k in sinks) |
62 | exports[k] = u.Sink(sinks[k]) |
63 | |
64 | var maybe = require('./maybe')(exports) |
65 | |
66 | for(var k in maybe) |
67 | exports[k] = maybe[k] |
68 | |
69 | exports.Duplex = |
70 | exports.Through = exports.pipeable = u.Through |
71 | exports.Source = exports.pipeableSource = u.Source |
72 | exports.Sink = exports.pipeableSink = u.Sink |
73 | |
74 | |
75 |
Built with git-ssb-web