Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support bigint stats in Nodejs v18.7+ #361

Merged
merged 2 commits into from
Aug 2, 2022
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
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