From d652e54e2396a47358a553c447e0f338b4c2dc67 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Thu, 22 Mar 2018 11:40:55 -0700 Subject: [PATCH 1/2] [Fix] Replace Buffer.from with `buffer-from` Restores node < 4 support --- index.js | 9 +++++---- package.json | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) 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..71b824e 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": { From 8dca458bd9a2c6b84d6e3a1996e41b242fe1c49a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 10 Jun 2025 14:24:56 -0700 Subject: [PATCH 2/2] [meta] temporarily limit support to node v0.10 Pending https://github.com/LinusU/buffer-from/issues/14 --- .github/workflows/node-aught.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/package.json b/package.json index 71b824e..65c014b 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,6 @@ ] }, "engines": { - "node": ">= 0.4" + "node": ">= 0.10" } }