-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix] Properly detect typed arrays (#85)
ArrayBuffer.isView method is not defined in IE10.
- Loading branch information
1 parent
f9c0625
commit 6b356eb
Showing
2 changed files
with
26 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
|
||
module.exports = isBuf; | ||
|
||
var withNativeBuffer = typeof global.Buffer === 'function' && typeof global.Buffer.isBuffer === 'function'; | ||
var withNativeArrayBuffer = typeof global.ArrayBuffer === 'function'; | ||
|
||
var isView = (function () { | ||
if (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 (global.Buffer && global.Buffer.isBuffer(obj)) || | ||
(global.ArrayBuffer && (obj instanceof ArrayBuffer || ArrayBuffer.isView(obj))); | ||
return (withNativeBuffer && global.Buffer.isBuffer(obj)) || | ||
(withNativeArrayBuffer && (obj instanceof global.ArrayBuffer || isView(obj))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters