I want to pipe data from an amazon kinesis stream to a an s3 log or a bunyan log.
The sample works with a file write stream or stdout. How would I implmeny my own writable stream?
//this works
var file = fs.createWriteStream('my.log')
kinesisSource.pipe(file)
this doesn't work saying it has no method 'on'
var stream = {}; //process.stdout works however
stream.writable = true;
stream.write =function(data){
console.log(data);
};
kinesisSource.pipe(stream);
what methods do I have to implement for my own custom writable stream, the docs seem to indicate I need to implement 'write' and not 'on'
Actually to create a writeable stream is quite simple. Here's is the example:
Also if you want to create your own class, @Paul give a good answer.
To create your own writable stream, you have three possibilities.
Create your own class
For this you'll need 1) to extend the Writable class 2) to call the Writable constructor in your own constructor 3) define a
_write()
method in the prototype of your stream object.Here's an example :
Extend an empty Writable object
Instead of defining a new object type, you can instanciate an empty
Writable
object and implement the_write()
method:Use the Simplified Constructor API
If you're using io.js, you can use the simplified constructor API:
Use an ES6 class in Node 4+