Files: c4caefd7c6cd6984ee0223c391cd4ce43118cf29 / index.js
1941 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] = pipeableSource(sources[k]) |
8 | |
9 | for(var k in throughs) |
10 | exports[k] = pipeable(throughs[k]) |
11 | |
12 | for(var k in sinks) |
13 | exports[k] = pipeableSink(sinks[k]) |
14 | |
15 | exports.pipeableSource = pipeableSource |
16 | exports.pipeable = pipeable |
17 | exports.pipeableSink = pipeableSink |
18 | |
19 | function addPipe(read) { |
20 | if('function' !== typeof read) |
21 | return read |
22 | |
23 | read.pipe = read.pipe || function (reader) { |
24 | if('function' != typeof reader) |
25 | throw new Error('must pipe to reader') |
26 | return addPipe(reader(read)) |
27 | } |
28 | |
29 | return read |
30 | } |
31 | |
32 | function pipeableSource (createRead) { |
33 | return function () { |
34 | var args = [].slice.call(arguments) |
35 | return addPipe(createRead.apply(null, args)) |
36 | } |
37 | } |
38 | |
39 | function pipeable (createRead) { |
40 | return function () { |
41 | var args = [].slice.call(arguments) |
42 | var piped = [] |
43 | function reader (read) { |
44 | args.unshift(read) |
45 | read = createRead.apply(null, args) |
46 | while(piped.length) |
47 | read = piped.shift()(read) |
48 | return read |
49 | //pipeing to from this reader should compose... |
50 | } |
51 | reader.pipe = function (read) { |
52 | piped.push(read) |
53 | return reader |
54 | } |
55 | return reader |
56 | } |
57 | } |
58 | |
59 | function pipeableSink(createReader) { |
60 | return function () { |
61 | var args = [].slice.call(arguments) |
62 | return function (read) { |
63 | args.unshift(read) |
64 | return createReader.apply(null, args) |
65 | } |
66 | } |
67 | } |
68 | |
69 | /* |
70 | var destack = function (n) { |
71 | var i = 0; n = n || 10, waiting = [], queued = false, ended = false |
72 | return function (readable) { |
73 | return function (reader) { |
74 | return reader(function (end, cb) { |
75 | ended = ended || end |
76 | if(i ++ < n) { |
77 | return readable(end, cb) |
78 | } else { |
79 | process.nextTick(function () { |
80 | i = 0 |
81 | readable(end, cb) |
82 | }) |
83 | } |
84 | }) |
85 | } |
86 | } |
87 | } |
88 | */ |
89 |
Built with git-ssb-web