Skip to content

Commit b9d4c6d

Browse files
authored
fix: add missing nanosecond-precision properties to Stats (#943)
1 parent b813101 commit b9d4c6d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Stats.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ export class Stats<T = TStatNumber> {
4242
stats.ctimeMs = ctimeMs;
4343
stats.birthtimeMs = ctimeMs;
4444

45+
if (bigint) {
46+
stats.atimeNs = BigInt(atime.getTime()) * BigInt(1000000);
47+
stats.mtimeNs = BigInt(mtime.getTime()) * BigInt(1000000);
48+
const ctimeNs = BigInt(ctime.getTime()) * BigInt(1000000);
49+
stats.ctimeNs = ctimeNs;
50+
stats.birthtimeNs = ctimeNs;
51+
}
52+
4553
stats.dev = getStatNumber(0);
4654
stats.mode = getStatNumber(node.mode);
4755
stats.nlink = getStatNumber(node.nlink);
@@ -68,6 +76,12 @@ export class Stats<T = TStatNumber> {
6876
ctimeMs: T;
6977
birthtimeMs: T;
7078

79+
// additional properties that exist when bigint is true
80+
atimeNs: T extends bigint ? T : undefined;
81+
mtimeNs: T extends bigint ? T : undefined;
82+
ctimeNs: T extends bigint ? T : undefined;
83+
birthtimeNs: T extends bigint ? T : undefined;
84+
7185
dev: T;
7286
mode: T;
7387
nlink: T;

src/__tests__/volume.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,10 @@ describe('volume', () => {
764764
if (hasBigInt) {
765765
const stats = vol.lstatSync('/dojo.js', { bigint: true });
766766
expect(typeof stats.ino).toBe('bigint');
767+
expect(typeof stats.atimeNs).toBe('bigint');
768+
expect(typeof stats.mtimeNs).toBe('bigint');
769+
expect(typeof stats.ctimeNs).toBe('bigint');
770+
expect(typeof stats.birthtimeNs).toBe('bigint');
767771
} else {
768772
expect(() => vol.lstatSync('/dojo.js', { bigint: true })).toThrowError();
769773
}
@@ -795,6 +799,10 @@ describe('volume', () => {
795799
if (hasBigInt) {
796800
const stats = vol.statSync('/dojo.js', { bigint: true });
797801
expect(typeof stats.ino).toBe('bigint');
802+
expect(typeof stats.atimeNs).toBe('bigint');
803+
expect(typeof stats.mtimeNs).toBe('bigint');
804+
expect(typeof stats.ctimeNs).toBe('bigint');
805+
expect(typeof stats.birthtimeNs).toBe('bigint');
798806
} else {
799807
expect(() => vol.statSync('/dojo.js', { bigint: true })).toThrowError();
800808
}
@@ -839,6 +847,10 @@ describe('volume', () => {
839847
if (hasBigInt) {
840848
const stats = vol.fstatSync(fd, { bigint: true });
841849
expect(typeof stats.ino).toBe('bigint');
850+
expect(typeof stats.atimeNs).toBe('bigint');
851+
expect(typeof stats.mtimeNs).toBe('bigint');
852+
expect(typeof stats.ctimeNs).toBe('bigint');
853+
expect(typeof stats.birthtimeNs).toBe('bigint');
842854
} else {
843855
expect(() => vol.fstatSync(fd, { bigint: true })).toThrowError();
844856
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy