From 365e062e14befd2c00cd281d6fe2d77e248320bf Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 19 Jun 2018 02:58:49 +0800 Subject: [PATCH] fs: add *timeNs properties to BigInt Stats objects - Extend the aliased buffer for stats objects to contain the entire time spec (seconds and nanoseconds) for the time values instead of calculating the milliseconds in C++ and lose precision there. - Calculate the nanosecond-precision time values in JS and expose them in BigInt Stats objects as `*timeNs`. The millisecond-precision values are now calculated from the nanosecond-precision values. PR-URL: https://github.com/nodejs/node/pull/21387 Reviewed-By: Jeremiah Senkpiel Reviewed-By: James M Snell Reviewed-By: Gus Caplan --- doc/api/fs.md | 71 +++++++++- lib/internal/fs/utils.js | 163 ++++++++++++++-------- src/env.h | 26 +++- src/node_file.cc | 11 +- src/node_file.h | 95 +++++-------- test/parallel/test-fs-stat-bigint.js | 20 +++ test/parallel/test-fs-watchfile-bigint.js | 18 ++- 7 files changed, 275 insertions(+), 129 deletions(-) diff --git a/doc/api/fs.md b/doc/api/fs.md index e7ecb354720cda..c61f0d4e3ef660 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -512,7 +512,8 @@ A `fs.Stats` object provides information about a file. Objects returned from [`fs.stat()`][], [`fs.lstat()`][] and [`fs.fstat()`][] and their synchronous counterparts are of this type. If `bigint` in the `options` passed to those methods is true, the numeric values -will be `bigint` instead of `number`. +will be `bigint` instead of `number`, and the object will contain additional +nanosecond-precision properties suffixed with `Ns`. ```console Stats { @@ -539,7 +540,7 @@ Stats { `bigint` version: ```console -Stats { +BigIntStats { dev: 2114n, ino: 48064969n, mode: 33188n, @@ -554,6 +555,10 @@ Stats { mtimeMs: 1318289051000n, ctimeMs: 1318289051000n, birthtimeMs: 1318289051000n, + atimeNs: 1318289051000000000n, + mtimeNs: 1318289051000000000n, + ctimeNs: 1318289051000000000n, + birthtimeNs: 1318289051000000000n, atime: Mon, 10 Oct 2011 23:24:11 GMT, mtime: Mon, 10 Oct 2011 23:24:11 GMT, ctime: Mon, 10 Oct 2011 23:24:11 GMT, @@ -726,6 +731,54 @@ added: v8.1.0 The timestamp indicating the creation time of this file expressed in milliseconds since the POSIX Epoch. +### stats.atimeNs + + +* {bigint} + +Only present when `bigint: true` is passed into the method that generates +the object. +The timestamp indicating the last time this file was accessed expressed in +nanoseconds since the POSIX Epoch. + +### stats.mtimeNs + + +* {bigint} + +Only present when `bigint: true` is passed into the method that generates +the object. +The timestamp indicating the last time this file was modified expressed in +nanoseconds since the POSIX Epoch. + +### stats.ctimeNs + + +* {bigint} + +Only present when `bigint: true` is passed into the method that generates +the object. +The timestamp indicating the last time the file status was changed expressed +in nanoseconds since the POSIX Epoch. + +### stats.birthtimeNs + + +* {bigint} + +Only present when `bigint: true` is passed into the method that generates +the object. +The timestamp indicating the creation time of this file expressed in +nanoseconds since the POSIX Epoch. + ### stats.atime