From 1e7645c39ae5213a44267cff3d599264c2211f1a Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 7 Apr 2018 17:01:06 +0800 Subject: fs: support BigInt in fs.*stat and fs.watchFile Add the `bigint: true` option to all the `fs.*stat` methods and `fs.watchFile`. PR-URL: https://github.com/nodejs/node/pull/20220 Fixes: https://github.com/nodejs/node/issues/12115 Reviewed-By: Ben Noordhuis --- lib/internal/fs/utils.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/internal/fs/utils.js') diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index a8c64e2b04..7092bbcb63 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -114,7 +114,7 @@ function preprocessSymlinkDestination(path, type, linkPath) { } function dateFromNumeric(num) { - return new Date(num + 0.5); + return new Date(Number(num) + 0.5); } // Constructor for file stats. @@ -155,7 +155,15 @@ function Stats( } Stats.prototype._checkModeProperty = function(property) { - return ((this.mode & S_IFMT) === property); + if (isWindows && (property === S_IFIFO || property === S_IFBLK || + property === S_IFSOCK)) { + return false; // Some types are not available on Windows + } + if (typeof this.mode === 'bigint') { // eslint-disable-line valid-typeof + // eslint-disable-next-line no-undef + return (this.mode & BigInt(S_IFMT)) === BigInt(property); + } + return (this.mode & S_IFMT) === property; }; Stats.prototype.isDirectory = function() { @@ -189,9 +197,9 @@ Stats.prototype.isSocket = function() { function getStatsFromBinding(stats, offset = 0) { return new Stats(stats[0 + offset], stats[1 + offset], stats[2 + offset], stats[3 + offset], stats[4 + offset], stats[5 + offset], - stats[6 + offset] < 0 ? undefined : stats[6 + offset], + isWindows ? undefined : stats[6 + offset], // blksize stats[7 + offset], stats[8 + offset], - stats[9 + offset] < 0 ? undefined : stats[9 + offset], + isWindows ? undefined : stats[9 + offset], // blocks stats[10 + offset], stats[11 + offset], stats[12 + offset], stats[13 + offset]); } -- cgit v1.2.3