You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
576 B

4 years ago
  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. }