index.js
function readableStream(stream) {
  return new Promise(function(resolve, reject) {
    var chunks = {
      data: []
    };

    function onData(chunk) {
      if (!chunks.type) {
        chunks.type = chunkTypes[typeof chunk];
      }

      chunks.data.push(chunk);
    }

    function onEnd() {
      if (chunks.type === chunkTypes.object) {
        resolve(Buffer.concat(chunks.data));
      }
      else {
        resolve(chunks.data.join(""));
      }
    }

    function onError(error) {
      reject(error);
    }

    stream
      .on("error", onError)
      .on("data", onData)
      .on("end", onEnd);
  });
}
function readableStream(stream) {
  return new Promise(function(resolve, reject) {
    var chunks = {
      data: []
    };

    function onData(chunk) {
      if (!chunks.type) {
        chunks.type = chunkTypes[typeof chunk];
      }

      chunks.data.push(chunk);
    }

    function onEnd() {
      if (chunks.type === chunkTypes.object) {
        resolve(Buffer.concat(chunks.data));
      }
      else {
        resolve(chunks.data.join(""));
      }
    }

    function onError(error) {
      reject(error);
    }

    stream
      .on("error", onError)
      .on("data", onData)
      .on("end", onEnd);
  });
}
function readableStream ( stream ) { return new Promise ( function ( resolve , reject ) { var chunks = { data : [ ] } ; function onData ( chunk ) { if ( ! chunks . type ) { chunks . type = chunkTypes [ typeof chunk ] ; } chunks . data . push ( chunk ) ; } function onEnd ( ) { if ( chunks . type === chunkTypes . object ) { resolve ( Buffer . concat ( chunks . data ) ) ; } else { resolve ( chunks . data . join ( "" ) ) ; } } function onError ( error ) { reject ( error ) ; } stream . on ( "error" , onError ) . on ( "data" , onData ) . on ( "end" , onEnd ) ; } ) ; }
Takes in a readable stream and returns a promise. The promise is resolved
when all the data is read. Or reject if the stream has errors.

@param {Stream} stream - Stream to read from to resolve the promise with.

@returns {Promise}
Takes in a readable stream and returns a promise . The promise is resolved when all the data is read . Or reject if the stream has errors .