Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node-aught.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var bufferFrom = require('buffer-from');
var isArray = require('isarray');

var useUint8Array = typeof Uint8Array !== 'undefined';
Expand All @@ -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);
}

/*
Expand All @@ -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
Expand All @@ -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);
}

/*
Expand All @@ -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.');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"homepage": "https://github.com/mafintosh/to-buffer",
"dependencies": {
"buffer-from": "^1.1.2",
"isarray": "^2.0.5"
},
"devDependencies": {
Expand All @@ -41,6 +42,6 @@
]
},
"engines": {
"node": ">= 0.4"
"node": ">= 0.10"
}
}