forked from BrowserSync/UI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.stream.js
84 lines (71 loc) · 2.04 KB
/
example.stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var through2 = require("through2");
var vinyl = require("vinyl");
var combiner = require('stream-combiner2');
var es = require('event-stream');
var inspect = require('util').inspect;
var Duplex = require("stream").Duplex;
var stream = new Duplex();
stream._read = function (out) {};
stream._write = function (out) {
this.push(out);
};
var fn1 = function (data, cb) {
cb(null, data + "shane");
};
var fn2 = function (data, cb) {
cb(null, data + " Osbourne");
};
//var stream = through2.obj(function (data, enc, next) {
// this.push(data);
// next();
//});
//var stream = new vinyl("hi");
stream
.pipe(es.map(fn1))
.pipe(es.map(fn2))
.pipe(through2.obj(function (out, enc, next) {
console.log(out);
}));
stream.write("Hi there: ");
//var fn = through2.obj(function (file, type, next) {
// console.log("Stream 1");
// this.push(file.concat([12, 23]));
// this.emit("error", new Error("Some error thing"));
// next();
//});
//
//var fn2 = through2.obj(function (file, type, next) {
// console.log("Stream 2");
// this.push(file.concat([5, 7]));
//});
//stream
// .pipe(fn)
// .pipe(fn2)
// .pipe(through2.obj(function (out) {
// console.log("Stream 3, out");
// console.log(out);
// }));
//var combinedStream = combiner.obj([
// stream,
// fn,
// fn2,
// through2.obj(function (out) {
// console.log("Stream 3, out");
// console.log(out);
// })
//]);
//
//stream.write([]);
//
//combinedStream.on("error", console.error.bind(console));
//if (!module.parent) {
// var es = require('event-stream');
// var inspect = require('util').inspect;
//
// process.stdin //connect streams together with `pipe`
// .pipe(es.split()) //split stream to break on newlines
// .pipe(es.map(function (data, cb) { //turn this async function into a stream
// cb(null, inspect(JSON.parse(data))); //render it nicely
// }))
// .pipe(process.stdout) // pipe it to stdout !
//}