git ssb

2+

Dominic / pull-stream



Tree: c4caefd7c6cd6984ee0223c391cd4ce43118cf29

Files: c4caefd7c6cd6984ee0223c391cd4ce43118cf29 / index.js

1941 bytesRaw
1
2var sources = require('./sources')
3var sinks = require('./sinks')
4var throughs = require('./throughs')
5
6for(var k in sources)
7 exports[k] = pipeableSource(sources[k])
8
9for(var k in throughs)
10 exports[k] = pipeable(throughs[k])
11
12for(var k in sinks)
13 exports[k] = pipeableSink(sinks[k])
14
15exports.pipeableSource = pipeableSource
16exports.pipeable = pipeable
17exports.pipeableSink = pipeableSink
18
19function 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
32function pipeableSource (createRead) {
33 return function () {
34 var args = [].slice.call(arguments)
35 return addPipe(createRead.apply(null, args))
36 }
37}
38
39function 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
59function 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/*
70var 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