index.js
function addListener(name) {
  if (name !== 'collect') {
    return;
  }

  if (this._collecting) {
    // Don't add more than once
    return;
  }

  debug('adding collect method', this._readableState.objectMode, this._readableState.encoding);

  let collected;
  if (this._readableState.objectMode) {
    collected = [];
  } else if (this._readableState.encoding === null) {
    collected = Buffer.from('');
  } else {
    collected = '';
  }

  this
    .on('readable', () => {
      let chunk;
      while ((chunk = this.read()) !== null) {
        debug('data', chunk);

        if (chunk !== null) {
          if (this._readableState.objectMode) {
            collected.push(chunk);
          } else if (this._readableState.encoding === null) {
            collected = Buffer.concat([collected, chunk]);
          } else {
            collected += chunk;
          }
        }
      }
    })
    .on('end', () => this.emit('collect', collected));

  this._collecting = true;
}
function addListener(name) {
  if (name !== 'collect') {
    return;
  }

  if (this._collecting) {
    // Don't add more than once
    return;
  }

  debug('adding collect method', this._readableState.objectMode, this._readableState.encoding);

  let collected;
  if (this._readableState.objectMode) {
    collected = [];
  } else if (this._readableState.encoding === null) {
    collected = Buffer.from('');
  } else {
    collected = '';
  }

  this
    .on('readable', () => {
      let chunk;
      while ((chunk = this.read()) !== null) {
        debug('data', chunk);

        if (chunk !== null) {
          if (this._readableState.objectMode) {
            collected.push(chunk);
          } else if (this._readableState.encoding === null) {
            collected = Buffer.concat([collected, chunk]);
          } else {
            collected += chunk;
          }
        }
      }
    })
    .on('end', () => this.emit('collect', collected));

  this._collecting = true;
}
function addListener ( name ) { if ( name !== 'collect' ) { return ; } if ( this . _collecting ) { // Don't add more than once return ; } debug ( 'adding collect method' , this . _readableState . objectMode , this . _readableState . encoding ) ; let collected ; if ( this . _readableState . objectMode ) { collected = [ ] ; } else if ( this . _readableState . encoding === null ) { collected = Buffer . from ( '' ) ; } else { collected = '' ; } this . on ( 'readable' , ( ) => { let chunk ; while ( ( chunk = this . read ( ) ) !== null ) { debug ( 'data' , chunk ) ; if ( chunk !== null ) { if ( this . _readableState . objectMode ) { collected . push ( chunk ) ; } else if ( this . _readableState . encoding === null ) { collected = Buffer . concat ( [ collected , chunk ] ) ; } else { collected += chunk ; } } } } ) . on ( 'end' , ( ) => this . emit ( 'collect' , collected ) ) ; this . _collecting = true ; }
When a listener for an event named collect is added start collecting the data
When a listener for an event named collect is added start collecting the data