Skip to content

Commit

Permalink
standard
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Mar 2, 2017
1 parent 2e9774f commit 8cd4515
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -73,7 +73,7 @@ If the browser doesn't support typed arrays, then `toBuffer` will create a new `
object, copy the data into it, and return it. There's no simple performance optimization
we can do for old browsers. Oh well.

If this module is used in node, then it will just call `new Buffer`. This is just for
If this module is used in node, then it will just call `Buffer.from`. This is just for
the convenience of modules that work in both node and the browser.

## license
Expand Down
6 changes: 3 additions & 3 deletions index.js
Expand Up @@ -12,14 +12,14 @@ var isTypedArray = require('is-typedarray').strict
module.exports = function typedarrayToBuffer (arr) {
if (isTypedArray(arr)) {
// To avoid a copy, use the typed array's underlying ArrayBuffer to back new Buffer
var buf = new Buffer(arr.buffer)
var buf = Buffer.from(arr.buffer)
if (arr.byteLength !== arr.buffer.byteLength) {
// Respect the "view", i.e. byteOffset and byteLength, without doing a copy
buf = buf.slice(arr.byteOffset, arr.byteOffset + arr.byteLength)
}
return buf
} else {
// Pass through all other types to the `Buffer` constructor
return new Buffer(arr)
// Pass through all other types to `Buffer.from`
return Buffer.from(arr)
}
}

0 comments on commit 8cd4515

Please sign in to comment.