UNPKG

typedarray-to-buffer

Version:

Convert a typed array to a Buffer without a copy

19 lines (18 loc) 581 B
/** * Convert a typed array to a Buffer without a copy * * Author: Feross Aboukhadijeh <feross@feross.org> <http://feross.org> * License: MIT * * `npm install typedarray-to-buffer` */ module.exports = function (arr) { if (typeof Buffer._augment === 'function' && Buffer._useTypedArrays) { // If `Buffer` is from the `buffer` module and this browser supports typed arrays, // then augment it with all the `Buffer` methods. return Buffer._augment(arr) } else { // Otherwise, fallback to creating a `Buffer` with a copy. return new Buffer(arr) } }