Skip to content

Commit

Permalink
fix: add missing nanosecond-precision properties to Stats (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo authored Sep 15, 2023
1 parent b813101 commit b9d4c6d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export class Stats<T = TStatNumber> {
stats.ctimeMs = ctimeMs;
stats.birthtimeMs = ctimeMs;

if (bigint) {
stats.atimeNs = BigInt(atime.getTime()) * BigInt(1000000);
stats.mtimeNs = BigInt(mtime.getTime()) * BigInt(1000000);
const ctimeNs = BigInt(ctime.getTime()) * BigInt(1000000);
stats.ctimeNs = ctimeNs;
stats.birthtimeNs = ctimeNs;
}

stats.dev = getStatNumber(0);
stats.mode = getStatNumber(node.mode);
stats.nlink = getStatNumber(node.nlink);
Expand All @@ -68,6 +76,12 @@ export class Stats<T = TStatNumber> {
ctimeMs: T;
birthtimeMs: T;

// additional properties that exist when bigint is true
atimeNs: T extends bigint ? T : undefined;
mtimeNs: T extends bigint ? T : undefined;
ctimeNs: T extends bigint ? T : undefined;
birthtimeNs: T extends bigint ? T : undefined;

dev: T;
mode: T;
nlink: T;
Expand Down
12 changes: 12 additions & 0 deletions src/__tests__/volume.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,10 @@ describe('volume', () => {
if (hasBigInt) {
const stats = vol.lstatSync('/dojo.js', { bigint: true });
expect(typeof stats.ino).toBe('bigint');
expect(typeof stats.atimeNs).toBe('bigint');
expect(typeof stats.mtimeNs).toBe('bigint');
expect(typeof stats.ctimeNs).toBe('bigint');
expect(typeof stats.birthtimeNs).toBe('bigint');
} else {
expect(() => vol.lstatSync('/dojo.js', { bigint: true })).toThrowError();
}
Expand Down Expand Up @@ -795,6 +799,10 @@ describe('volume', () => {
if (hasBigInt) {
const stats = vol.statSync('/dojo.js', { bigint: true });
expect(typeof stats.ino).toBe('bigint');
expect(typeof stats.atimeNs).toBe('bigint');
expect(typeof stats.mtimeNs).toBe('bigint');
expect(typeof stats.ctimeNs).toBe('bigint');
expect(typeof stats.birthtimeNs).toBe('bigint');
} else {
expect(() => vol.statSync('/dojo.js', { bigint: true })).toThrowError();
}
Expand Down Expand Up @@ -839,6 +847,10 @@ describe('volume', () => {
if (hasBigInt) {
const stats = vol.fstatSync(fd, { bigint: true });
expect(typeof stats.ino).toBe('bigint');
expect(typeof stats.atimeNs).toBe('bigint');
expect(typeof stats.mtimeNs).toBe('bigint');
expect(typeof stats.ctimeNs).toBe('bigint');
expect(typeof stats.birthtimeNs).toBe('bigint');
} else {
expect(() => vol.fstatSync(fd, { bigint: true })).toThrowError();
}
Expand Down

0 comments on commit b9d4c6d

Please sign in to comment.