Skip to content

Commit 147e5dd

Browse files
committed
fix: support bigint stats in Nodejs v18.7+
closes #359
1 parent f696b2c commit 147e5dd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/item.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
'use strict';
22

3+
const fsBinding = process.binding('fs');
4+
const statsConstructor = fsBinding.statValues
5+
? fsBinding.statValues.constructor
6+
: Float64Array;
7+
// Nodejs v18.7.0 changed bigint stats type from BigUint64Array to BigInt64Array
8+
// https://github.com/nodejs/node/pull/43714
9+
const bigintStatsConstructor = fsBinding.bigintStatValues
10+
? fsBinding.bigintStatValues.constructor
11+
: BigUint64Array;
12+
313
let counter = 0;
414

515
/**
@@ -280,7 +290,9 @@ Item.prototype.setGid = function(gid) {
280290
* @return {Object} Stats properties.
281291
*/
282292
Item.prototype.getStats = function(bigint) {
283-
const stats = bigint ? new BigUint64Array(36) : new Float64Array(36);
293+
const stats = bigint
294+
? new bigintStatsConstructor(36)
295+
: new statsConstructor(36);
284296
const convert = bigint ? v => BigInt(v) : v => v;
285297

286298
stats[0] = convert(8675309); // dev

0 commit comments

Comments
 (0)