git ssb

2+

Dominic / pull-stream



Tree: 8a69c2e9c2cee69cd220830ceb1e29bf92d40ca0

Files: 8a69c2e9c2cee69cd220830ceb1e29bf92d40ca0 / index.js

2401 bytesRaw
1
2var sources = require('./sources')
3var sinks = require('./sinks')
4var throughs = require('./throughs')
5
6for(var k in sources)
7 exports[k] = Source(sources[k])
8
9for(var k in throughs)
10 exports[k] = Through(throughs[k])
11
12for(var k in sinks)
13 exports[k] = Sink(sinks[k])
14
15exports.Duplex =
16exports.Through = exports.pipeable = Through
17exports.Source = exports.pipeableSource = Source
18exports.Sink = exports.pipeableSink = Sink
19
20exports.addPipe = addPipe
21exports.addReaderPipe
22 = addReaderPipe
23
24function 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
37function Source (createRead) {
38 return function () {
39 var args = [].slice.call(arguments)
40 return addPipe(createRead.apply(null, args))
41 }
42}
43
44function 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
60function 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
80function 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/*
91var 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