git ssb

2+

Dominic / pull-stream



Commit 9e3584c7f2ccc9625546b554598ed80ccf660d0d

headers

Dominic Tarr committed on 3/22/2013, 8:40:05 AM
Parent: 139b6be7f1e796c60b1d5442a0e52e46373a5928

Files changed

README.mdchanged
README.mdView
@@ -8,8 +8,26 @@
88 data is pulled out of the source stream, into the destination.
99
1010 `pull-stream` is an minimal take on pull streams.
1111
12+## Examples
13+
14+What if implementing a stream was this simple:
15+
16+### Pipeable
17+
18+``` js
19+var pipeable = require('pull-stream').pipeable
20+
21+var createStream = pipeable(function (readable) {
22+ return function read (end, cb) {
23+ readable(end, cb)
24+ }
25+})
26+```
27+
28+### Readable & Reader vs. Readable & Writable
29+
1230 Instead of a readable stream, and a writable stream, there is a `readable` stream,
1331 and a `reader` stream.
1432
1533 the readable stream is just a function, that may be called many times,
@@ -52,8 +70,10 @@
5270 that do input _and_ output.
5371
5472 Simple!
5573
74+### Duplex
75+
5676 ``` js
5777 var map = function (readable, map) {
5878 //return a readable function!
5979 return function (end, cb) {
@@ -65,8 +85,10 @@
6585 ```
6686
6787 join them together!
6888
89+### function composition style "pipe"
90+
6991 ``` js
7092 logger(
7193 map(randomReadable, function (e) {
7294 return Math.round(e * 1000)
@@ -75,8 +97,10 @@
7597
7698 That is good -- but it's kinda weird, because we are used to left to right syntax
7799 for streams... `ls | grep | wc -l`
78100
101+### pipeability
102+
79103 So, we want to pass in the `readable` and `reader` function!
80104 It needs to be that order, so that it reads left to right.
81105
82106 A basic duplex function would look like this:
@@ -117,8 +141,11 @@
117141 ```
118142
119143 The `reader` stream is the same as before!
120144
145+
146+### Left-to-Right pipe
147+
121148 Now PIPE THEM TOGETHER!
122149
123150 ``` js
124151 randomReader2 (multiply) (logger)

Built with git-ssb-web