Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80540 views
1
var pipeline = require('../');
2
var through = require('through2');
3
var stringify = require('JSONStream').stringify;
4
var split = require('split');
5
var concat = require('concat-stream');
6
var test = require('tape');
7
8
test('nested middle splicer', function (t) {
9
t.plan(1);
10
11
var addNewLines = through(function (buf, enc, next) {
12
this.push(buf + '\n');
13
next();
14
});
15
16
var stream = pipeline.obj([
17
through.obj(function (str, enc, next) {
18
this.push(str.replace(/^./, function (c) {
19
return String.fromCharCode(c.charCodeAt(0) + 5);
20
}));
21
next();
22
}),
23
[ split(), addNewLines ],
24
through(function (buf, enc, next) {
25
this.push('> ' + buf);
26
next()
27
})
28
]);
29
30
stream.get(1).unshift(through(function (buf, enc, next) {
31
this.push(buf.toString('utf8').toUpperCase());
32
next();
33
}));
34
35
stream.pipe(concat(function (body) {
36
t.deepEqual(body.toString(), '> F\n> G\n> H\n');
37
}));
38
39
stream.write('a\n');
40
stream.write('b\n');
41
stream.write('c');
42
stream.end();
43
});
44
45