假设这customWS
是一个可写流..
util.inherits(customWS, stream.Writable);
我们实现我们的逻辑来处理_write()
如下所示的写入..
customWS.prototype._write = function(chunk, encoding, done) {
// ...
}
现在要使用customWS
该类,我们将执行以下操作..
aReadableStream.pipe(new customWS()).on('finish', callback);
那么callback
函数的参数是什么?
我可以通过一个callback
喜欢..
function(data) {
// ...
}
..还是固定的?
如果它不固定那么如何在customWS
类中实现这样的回调?
有什么像..
// in the implementation of customWS class
customWS.prototype._finish = function(user_specified_callback) {
user_specified_callback(some_data_say_a_bool_val);
}
// in the code, where i use the customWS class
aReadableStream.pipe(new customWS()).on('finish', function(flag) {
if (flag) {
console.log('yes');
}
});