Skip to content

Commit

Permalink
Merge pull request #361 from tschaub/fix-node-18.7
Browse files Browse the repository at this point in the history
fix: support bigint stats in Nodejs v18.7+
  • Loading branch information
tschaub committed Aug 2, 2022
2 parents b40f85b + 5f78fa9 commit 2da6d32
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- 12
- 14
- 16
- 18

steps:
- name: Clone repository
Expand Down
14 changes: 13 additions & 1 deletion lib/item.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
'use strict';

const fsBinding = process.binding('fs');
const statsConstructor = fsBinding.statValues
? fsBinding.statValues.constructor
: Float64Array;
// Nodejs v18.7.0 changed bigint stats type from BigUint64Array to BigInt64Array
// https://github.com/nodejs/node/pull/43714
const bigintStatsConstructor = fsBinding.bigintStatValues
? fsBinding.bigintStatValues.constructor
: BigUint64Array;

let counter = 0;

/**
Expand Down Expand Up @@ -280,7 +290,9 @@ Item.prototype.setGid = function(gid) {
* @return {Object} Stats properties.
*/
Item.prototype.getStats = function(bigint) {
const stats = bigint ? new BigUint64Array(36) : new Float64Array(36);
const stats = bigint
? new bigintStatsConstructor(36)
: new statsConstructor(36);
const convert = bigint ? v => BigInt(v) : v => v;

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

0 comments on commit 2da6d32

Please # to comment.