is-buffer.js 576 B

1234567891011121314151617181920
  1. module.exports = isBuf;
  2. var withNativeBuffer = typeof Buffer === 'function' && typeof Buffer.isBuffer === 'function';
  3. var withNativeArrayBuffer = typeof ArrayBuffer === 'function';
  4. var isView = function (obj) {
  5. return typeof ArrayBuffer.isView === 'function' ? ArrayBuffer.isView(obj) : (obj.buffer instanceof ArrayBuffer);
  6. };
  7. /**
  8. * Returns true if obj is a buffer or an arraybuffer.
  9. *
  10. * @api private
  11. */
  12. function isBuf(obj) {
  13. return (withNativeBuffer && Buffer.isBuffer(obj)) ||
  14. (withNativeArrayBuffer && (obj instanceof ArrayBuffer || isView(obj)));
  15. }