index.js 698 B

123456789101112131415161718192021
  1. /*!
  2. * Determine if an object is a Buffer
  3. *
  4. * @author Feross Aboukhadijeh <https://feross.org>
  5. * @license MIT
  6. */
  7. // The _isBuffer check is for Safari 5-7 support, because it's missing
  8. // Object.prototype.constructor. Remove this eventually
  9. module.exports = function (obj) {
  10. return obj != null && (isBuffer(obj) || isSlowBuffer(obj) || !!obj._isBuffer)
  11. }
  12. function isBuffer (obj) {
  13. return !!obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj)
  14. }
  15. // For Node v0.10 support. Remove this eventually.
  16. function isSlowBuffer (obj) {
  17. return typeof obj.readFloatLE === 'function' && typeof obj.slice === 'function' && isBuffer(obj.slice(0, 0))
  18. }