Files
socket.io/is-buffer.js
Damien Arrachequesne dc4f475a45 [revert] Move binary detection to the parser
So that we can skip the binary check.
2018-02-28 21:55:26 +01:00

25 lines
712 B
JavaScript

module.exports = isBuf;
var withNativeBuffer = typeof global.Buffer === 'function' && typeof global.Buffer.isBuffer === 'function';
var withNativeArrayBuffer = typeof global.ArrayBuffer === 'function';
var isView = (function () {
if (withNativeArrayBuffer && typeof global.ArrayBuffer.isView === 'function') {
return global.ArrayBuffer.isView;
} else {
return function (obj) { return obj.buffer instanceof global.ArrayBuffer; };
}
})();
/**
* Returns true if obj is a buffer or an arraybuffer.
*
* @api private
*/
function isBuf(obj) {
return (withNativeBuffer && global.Buffer.isBuffer(obj)) ||
(withNativeArrayBuffer && (obj instanceof global.ArrayBuffer || isView(obj)));
}