From 147e5ddfd63d7ac92d72328b00b7f33eba6059a8 Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Tue, 2 Aug 2022 21:24:27 +1000 Subject: [PATCH 1/2] fix: support bigint stats in Nodejs v18.7+ closes #359 --- lib/item.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/item.js b/lib/item.js index 1add72f..5cf17e6 100644 --- a/lib/item.js +++ b/lib/item.js @@ -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; /** @@ -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 From 5f78fa9cb236099e116083dc5ad813b108961f39 Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Tue, 2 Aug 2022 21:29:44 +1000 Subject: [PATCH 2/2] test: add nodejs v18 to CI --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0793812..850ff72 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,7 @@ jobs: - 12 - 14 - 16 + - 18 steps: - name: Clone repository