Skip to content

Commit c777496

Browse files
author
James Halliday
committed
docs
1 parent 9b6963d commit c777496

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

readme.markdown

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# labeled-stream-splicer
2+
3+
[splicable stream pipeline](https://npmjs.org/package/stream-splicer) with labels
4+
5+
# example
6+
7+
Here's an example that exposes a label for `deps` and `pack`:
8+
9+
``` js
10+
var splicer = require('labeled-stream-splicer');
11+
var through = require('through2');
12+
var deps = require('module-deps');
13+
var pack = require('browser-pack');
14+
15+
var pipeline = splicer.obj([
16+
'deps', [ deps(__dirname + '/browser/main.js') ],
17+
'pack', [ pack({ raw: true }) ],
18+
process.stdout
19+
]);
20+
21+
pipeline.get('deps').push(through.obj(function (row, enc, next) {
22+
row.source = row.source.toUpperCase();
23+
this.push(row);
24+
next();
25+
}));
26+
```
27+
28+
Here the `deps` sub-pipeline is augmented with a post-transformation that
29+
uppercases its source input.
30+
31+
# methods
32+
33+
``` js
34+
var splicer = require('labeled-stream-splicer')
35+
```
36+
37+
The API is the same as
38+
[stream-splicer](https://npmjs.org/package/stream-splicer),
39+
except that `pipeline.get()`, `pipeline.splice()`, and `pipeline.indexOf()` can
40+
accept string labels in addition to numeric indexes.
41+
42+
## var pipeline = splicer(streams, opts)
43+
44+
Create a `pipeline` duplex stream given an array of `streams`. Each `stream`
45+
will be piped to the next. Writes to `pipeline` get written to the first stream
46+
and data for reads from `pipeline` come from the last stream.
47+
48+
To signify a label, a stream may have a `.label` property or a string may be
49+
placed in the `streams` array.
50+
51+
For example, for streams `[ a, 'foo', b, c, 'bar', d ]`, this pipeline is
52+
constructed internally:
53+
54+
```
55+
a.pipe(b).pipe(c).pipe(d)
56+
```
57+
58+
with a label `'foo`' that points to `b` and a label `'bar'` that points to `d`.
59+
If `a` or `c` has a `.label` property, that label would be used for addressing.
60+
61+
Input will get written into `a`. Output will be read from `d`.
62+
63+
If any of the elements in `streams` are arrays, they will be converted into
64+
nested labeled pipelines. This is useful if you want to expose a hookable
65+
pipeline with grouped insertion points.
66+
67+
## var pipeline = splicer.obj(streams, opts)
68+
69+
Create a `pipeline` with `opts.objectMode` set to true for convenience.
70+
71+
## var removed = pipeline.splice(index, howMany, stream, ...)
72+
73+
Splice the pipeline starting at `index`, removing `howMany` streams and
74+
replacing them with each additional `stream` argument provided.
75+
76+
The streams that were removed from the splice and returned.
77+
78+
`index` can be an integer index or a label.
79+
80+
## pipeline.push(stream, ...)
81+
82+
Push one or more streams to the end of the pipeline.
83+
84+
The stream arguments may have a `label` property that will be used for string
85+
lookups.
86+
87+
## var stream = pipeline.pop()
88+
89+
Pop a stream from the end of the pipeline.
90+
91+
## pipeline.unshift(stream, ...)
92+
93+
Unshift one or more streams to the begining of the pipeline.
94+
95+
The stream arguments may have a `label` property that will be used for string
96+
lookups.
97+
98+
## var stream = pipeline.shift()
99+
100+
Shift a stream from the begining of the pipeline.
101+
102+
## var stream = pipeline.get(index)
103+
104+
Return the stream at index `index`.
105+
106+
`index` can be an integer or a string label.
107+
108+
# install
109+
110+
With [npm](https://npmjs.org) do:
111+
112+
```
113+
npm install labeled-stream-splicer
114+
```
115+
116+
# license
117+
118+
MIT

0 commit comments

Comments
 (0)