index.js 305 B

1234567891011121314
  1. module.exports = function (stream, cb) {
  2. var chunks = []
  3. stream.on('data', function (chunk) {
  4. chunks.push(chunk)
  5. })
  6. stream.once('end', function () {
  7. if (cb) cb(null, Buffer.concat(chunks))
  8. cb = null
  9. })
  10. stream.once('error', function (err) {
  11. if (cb) cb(err)
  12. cb = null
  13. })
  14. }