Skip to content

Commit 8e01307

Browse files
committed
[Refactor] use safe-buffer.from instead of buffer-from
1 parent d9a0dea commit 8e01307

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

.github/workflows/node-aught.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
tests:
77
uses: ljharb/actions/.github/workflows/node.yml@main
88
with:
9-
range: '>= 0.10 < 10'
9+
range: '< 10'
1010
type: minors
1111
command: npm run tests-only
1212

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
var Buffer = require('safe-buffer').Buffer;
4-
var bufferFrom = require('buffer-from');
54
var isArray = require('isarray');
65

76
var useUint8Array = typeof Uint8Array !== 'undefined';
@@ -21,7 +20,7 @@ module.exports = function toBuffer(data, encoding) {
2120

2221
// Convert strings to Buffer
2322
if (typeof data === 'string') {
24-
return bufferFrom(data, encoding);
23+
return Buffer.from(data, encoding);
2524
}
2625

2726
/*
@@ -34,7 +33,7 @@ module.exports = function toBuffer(data, encoding) {
3433
return Buffer.alloc(0);
3534
}
3635

37-
var res = bufferFrom(data.buffer, data.byteOffset, data.byteLength);
36+
var res = Buffer.from(data.buffer, data.byteOffset, data.byteLength);
3837
/*
3938
* Recheck result size, as offset/length doesn't work on Node.js <5.10
4039
* We just go to Uint8Array case if this fails
@@ -49,7 +48,7 @@ module.exports = function toBuffer(data, encoding) {
4948
* Doesn't make sense with other TypedArray instances
5049
*/
5150
if (useUint8Array && data instanceof Uint8Array) {
52-
return bufferFrom(data);
51+
return Buffer.from(data);
5352
}
5453

5554
/*
@@ -66,7 +65,7 @@ module.exports = function toBuffer(data, encoding) {
6665
&& data.constructor.isBuffer(data)
6766
)
6867
) {
69-
return bufferFrom(data);
68+
return Buffer.from(data);
7069
}
7170

7271
throw new TypeError('The "data" argument must be a string, an Array, a Buffer, a TypedArray, or a DataView.');

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
},
2626
"homepage": "https://github.com/mafintosh/to-buffer",
2727
"dependencies": {
28-
"buffer-from": "^1.1.2",
2928
"isarray": "^2.0.5",
3029
"safe-buffer": "^5.2.1"
3130
},
@@ -41,7 +40,7 @@
4140
"tape": "^5.9.0"
4241
},
4342
"engines": {
44-
"node": ">= 0.10"
43+
"node": ">= 0.4"
4544
},
4645
"publishConfig": {
4746
"ignore": [

0 commit comments

Comments
 (0)