0

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');
    }
  });
4

1 に答える 1