【发布时间】:2016-07-24 03:57:57
【问题描述】:
假设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');
}
});
【问题讨论】: