11'use strict' ;
22
3+ var bufferFrom = require ( 'buffer-from' ) ;
34var isArray = require ( 'isarray' ) ;
45
56var useUint8Array = typeof Uint8Array !== 'undefined' ;
@@ -19,7 +20,7 @@ module.exports = function toBuffer(data, encoding) {
1920
2021 // Convert strings to Buffer
2122 if ( typeof data === 'string' ) {
22- return Buffer . from ( data , encoding ) ;
23+ return bufferFrom ( data , encoding ) ;
2324 }
2425
2526 /*
@@ -32,7 +33,7 @@ module.exports = function toBuffer(data, encoding) {
3233 return Buffer . alloc ( 0 ) ;
3334 }
3435
35- var res = Buffer . from ( data . buffer , data . byteOffset , data . byteLength ) ;
36+ var res = bufferFrom ( data . buffer , data . byteOffset , data . byteLength ) ;
3637 /*
3738 * Recheck result size, as offset/length doesn't work on Node.js <5.10
3839 * We just go to Uint8Array case if this fails
@@ -47,7 +48,7 @@ module.exports = function toBuffer(data, encoding) {
4748 * Doesn't make sense with other TypedArray instances
4849 */
4950 if ( useUint8Array && data instanceof Uint8Array ) {
50- return Buffer . from ( data ) ;
51+ return bufferFrom ( data ) ;
5152 }
5253
5354 /*
@@ -64,7 +65,7 @@ module.exports = function toBuffer(data, encoding) {
6465 && data . constructor . isBuffer ( data )
6566 )
6667 ) {
67- return Buffer . from ( data ) ;
68+ return bufferFrom ( data ) ;
6869 }
6970
7071 throw new TypeError ( 'The "data" argument must be a string, an Array, a Buffer, a TypedArray, or a DataView.' ) ;
0 commit comments