index.js 392 B

123456789101112131415
  1. /*! simple-concat. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  2. module.exports = function (stream, cb) {
  3. var chunks = []
  4. stream.on('data', function (chunk) {
  5. chunks.push(chunk)
  6. })
  7. stream.once('end', function () {
  8. if (cb) cb(null, Buffer.concat(chunks))
  9. cb = null
  10. })
  11. stream.once('error', function (err) {
  12. if (cb) cb(err)
  13. cb = null
  14. })
  15. }