WritableStream to write to multi-WritableStreams. [Node.js]
$ npm install multiwriter
OR
$ git clone git://github.com/shinout/multiwriter.git
var mwriter = require('multiwriter').create({
stdout: process.stdout,
file1 : "file1",
file2 : "file2"
});
mwriter.write("this is written to all writable streams\n");
mwriter.stdout.write("this is written only to process.stdout\n");
mwriter.end(); // all writer ends
mwriter.on("close", function() {
console.log("all writers are closed instead of process.stdout.");
}); // all writer ends
MultiWriter implements interface of WritableStream.
See Node.js#Stream for WritableStream's API.
- MultiWriter.create(source, options)
- writer[name]
Creates an instance of MultiWriter.
obj is the pairs of key - values to register child writable streams.
key is the name of a child writable stream.
value is one of the followings.
- filename (string) : filename to write.
- wstream (WritableStream) instance of WritableStream.
(Object) options is optional.
key | type | description | example |
---|---|---|---|
interval | integer | the interval to write data. default 0 (writes every time) |
100 |
var mwriter = require('multiwriter').create({
stdout: process.stdout,
file1 : "file1",
file2 : "file2"
}, {interval: 300 });
We can access child writable streams.
var mwriter = require('multiwriter').create({
stdout: process.stdout,
file1 : "file1",
file2 : "file2"
}, {interval: 300 });
mwriter.file1.write("this is written only to file1");