tra-analysis/website/functions/node_modules/bun/example.js
2019-01-06 13:14:45 -06:00

28 lines
642 B
JavaScript

#!/usr/bin/env node
var stream = require("readable-stream"),
bun = require("./lib/bun");
// stream generator
var createStream = function createStream(id) {
var s = new stream.Transform({encoding: "utf8"});
s._transform = function _transform(str, encoding, done) {
this.push("(" + id + " " + str + ")");
done();
};
return s;
};
// create some streams
var streams = ["G", "O", "D"].map(function(id) {
return createStream(id);
});
// wrap the streams in a bun!
var hotdog = bun(streams);
// connect hotdog to stdout
hotdog.pipe(process.stdout);
// use the hotdog
hotdog.write("in a bun"); // (D (O (G in a bun)))