diff --git a/.github/workflows/node-aught.yml b/.github/workflows/node-aught.yml index c49d417..496d1dd 100644 --- a/.github/workflows/node-aught.yml +++ b/.github/workflows/node-aught.yml @@ -6,7 +6,7 @@ jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: - range: '< 10' + range: '>= 0.10 < 10' type: minors command: npm run tests-only diff --git a/index.js b/index.js index e15fcda..798ca39 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ 'use strict'; +var bufferFrom = require('buffer-from'); var isArray = require('isarray'); var useUint8Array = typeof Uint8Array !== 'undefined'; @@ -19,7 +20,7 @@ module.exports = function toBuffer(data, encoding) { // Convert strings to Buffer if (typeof data === 'string') { - return Buffer.from(data, encoding); + return bufferFrom(data, encoding); } /* @@ -32,7 +33,7 @@ module.exports = function toBuffer(data, encoding) { return Buffer.alloc(0); } - var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength); + var res = bufferFrom(data.buffer, data.byteOffset, data.byteLength); /* * Recheck result size, as offset/length doesn't work on Node.js <5.10 * We just go to Uint8Array case if this fails @@ -47,7 +48,7 @@ module.exports = function toBuffer(data, encoding) { * Doesn't make sense with other TypedArray instances */ if (useUint8Array && data instanceof Uint8Array) { - return Buffer.from(data); + return bufferFrom(data); } /* @@ -64,7 +65,7 @@ module.exports = function toBuffer(data, encoding) { && data.constructor.isBuffer(data) ) ) { - return Buffer.from(data); + return bufferFrom(data); } throw new TypeError('The "data" argument must be a string, an Array, a Buffer, a TypedArray, or a DataView.'); diff --git a/package.json b/package.json index 6e98007..65c014b 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "homepage": "https://github.com/mafintosh/to-buffer", "dependencies": { + "buffer-from": "^1.1.2", "isarray": "^2.0.5" }, "devDependencies": { @@ -41,6 +42,6 @@ ] }, "engines": { - "node": ">= 0.4" + "node": ">= 0.10" } }