index.js
function collect(stream, encoding, cb = () => {}) {
  if (typeof encoding === 'function') {
    cb = encoding;
    encoding = null;
  }

  return stream
    .pipe(new Collect({ encoding, objectMode: stream._readableState.objectMode }))
    .collect()
    .then((data) => {
      cb(null, data);
      return data;
    })
    .catch((e) => {
      cb(e);
      throw e;
    });
}
function collect(stream, encoding, cb = () => {}) {
  if (typeof encoding === 'function') {
    cb = encoding;
    encoding = null;
  }

  return stream
    .pipe(new Collect({ encoding, objectMode: stream._readableState.objectMode }))
    .collect()
    .then((data) => {
      cb(null, data);
      return data;
    })
    .catch((e) => {
      cb(e);
      throw e;
    });
}
function collect ( stream , encoding , cb = ( ) => { } ) { if ( typeof encoding === 'function' ) { cb = encoding ; encoding = null ; } return stream . pipe ( new Collect ( { encoding , objectMode : stream . _readableState . objectMode } ) ) . collect ( ) . then ( ( data ) => { cb ( null , data ) ; return data ; } ) . catch ( ( e ) => { cb ( e ) ; throw e ; } ) ; }
Collect all data in a stream and return as a promise or in a callback
@param {Stream} stream A stream
@param {String} [encoding] Stream encoding - optional
@param {Function} cb Callback, the first argument will be the data
@returns {Promise}
Collect all data in a stream and return as a promise or in a callback