Files: 545734ec6384c1b2b71f539ea4acfe56af123b1e / index.js
2401 bytesRaw
1 | |
2 | var sources = require('./sources') |
3 | var sinks = require('./sinks') |
4 | var throughs = require('./throughs') |
5 | |
6 | for(var k in sources) |
7 | exports[k] = Source(sources[k]) |
8 | |
9 | for(var k in throughs) |
10 | exports[k] = Through(throughs[k]) |
11 | |
12 | for(var k in sinks) |
13 | exports[k] = Sink(sinks[k]) |
14 | |
15 | exports.Duplex = |
16 | exports.Through = exports.pipeable = Through |
17 | exports.Source = exports.pipeableSource = Source |
18 | exports.Sink = exports.pipeableSink = Sink |
19 | |
20 | exports.addPipe = addPipe |
21 | exports.addReaderPipe |
22 | = addReaderPipe |
23 | |
24 | function addPipe(read) { |
25 | if('function' !== typeof read) |
26 | return read |
27 | |
28 | read.pipe = read.pipe || function (reader) { |
29 | if('function' != typeof reader) |
30 | throw new Error('must pipe to reader') |
31 | return addPipe(reader(read)) |
32 | } |
33 | |
34 | return read |
35 | } |
36 | |
37 | function Source (createRead) { |
38 | return function () { |
39 | var args = [].slice.call(arguments) |
40 | return addPipe(createRead.apply(null, args)) |
41 | } |
42 | } |
43 | |
44 | function addReaderPipe(reader) { |
45 | var piped = [] |
46 | function _reader (read) { |
47 | read = reader(read) |
48 | while(piped.length) |
49 | read = piped.shift()(read) |
50 | return read |
51 | //pipeing to from this reader should compose... |
52 | } |
53 | _reader.pipe = function (read) { |
54 | piped.push(read) |
55 | return reader |
56 | } |
57 | return _reader |
58 | } |
59 | |
60 | function Through (createRead) { |
61 | return function () { |
62 | var args = [].slice.call(arguments) |
63 | var piped = [] |
64 | function reader (read) { |
65 | args.unshift(read) |
66 | read = createRead.apply(null, args) |
67 | while(piped.length) |
68 | read = piped.shift()(read) |
69 | return read |
70 | //pipeing to from this reader should compose... |
71 | } |
72 | reader.pipe = function (read) { |
73 | piped.push(read) |
74 | return reader |
75 | } |
76 | return reader |
77 | } |
78 | } |
79 | |
80 | function Sink(createReader) { |
81 | return function () { |
82 | var args = [].slice.call(arguments) |
83 | return function (read) { |
84 | args.unshift(read) |
85 | return createReader.apply(null, args) |
86 | } |
87 | } |
88 | } |
89 | |
90 | /* |
91 | var destack = function (n) { |
92 | var i = 0; n = n || 10, waiting = [], queued = false, ended = false |
93 | return function (readable) { |
94 | return function (reader) { |
95 | return reader(function (end, cb) { |
96 | ended = ended || end |
97 | if(i ++ < n) { |
98 | return readable(end, cb) |
99 | } else { |
100 | process.nextTick(function () { |
101 | i = 0 |
102 | readable(end, cb) |
103 | }) |
104 | } |
105 | }) |
106 | } |
107 | } |
108 | } |
109 | */ |
110 |
Built with git-ssb-web