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.

24 lines
712 B

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