Skip to content

Commit

Permalink
fs: load dates lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Nov 25, 2023
1 parent 7981e2e commit 3f648cd
Showing 1 changed file with 81 additions and 8 deletions.
89 changes: 81 additions & 8 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
NumberIsFinite,
MathMin,
MathRound,
ObjectDefineProperty,
ObjectIs,
ObjectSetPrototypeOf,
ReflectApply,
Expand Down Expand Up @@ -462,15 +463,51 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize,
this.mtimeNs = mtimeNs;
this.ctimeNs = ctimeNs;
this.birthtimeNs = birthtimeNs;
this.atime = dateFromMs(this.atimeMs);
this.mtime = dateFromMs(this.mtimeMs);
this.ctime = dateFromMs(this.ctimeMs);
this.birthtime = dateFromMs(this.birthtimeMs);
}

ObjectSetPrototypeOf(BigIntStats.prototype, StatsBase.prototype);
ObjectSetPrototypeOf(BigIntStats, StatsBase);

ObjectDefineProperty(BigIntStats.prototype, 'atime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.atimeMs);
ObjectDefineProperty(this, 'atime', { __proto__: null, value });
return this.atime;
},
});

ObjectDefineProperty(BigIntStats.prototype, 'mtime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.mtimeMs);
ObjectDefineProperty(this, 'mtime', { __proto__: null, value });
return this.mtime;
},
});

ObjectDefineProperty(BigIntStats.prototype, 'ctime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.ctimeMs);
ObjectDefineProperty(this, 'ctime', { __proto__: null, value });
return this.ctime;
},
});

ObjectDefineProperty(BigIntStats.prototype, 'birthtime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.birthtimeMs);
ObjectDefineProperty(this, 'birthtime', { __proto__: null, value });
return this.birthtime;
},
});

BigIntStats.prototype._checkModeProperty = function(property) {
if (isWindows && (property === S_IFIFO || property === S_IFBLK ||
property === S_IFSOCK)) {
Expand All @@ -488,15 +525,51 @@ function Stats(dev, mode, nlink, uid, gid, rdev, blksize,
this.mtimeMs = mtimeMs;
this.ctimeMs = ctimeMs;
this.birthtimeMs = birthtimeMs;
this.atime = dateFromMs(atimeMs);
this.mtime = dateFromMs(mtimeMs);
this.ctime = dateFromMs(ctimeMs);
this.birthtime = dateFromMs(birthtimeMs);
}

ObjectSetPrototypeOf(Stats.prototype, StatsBase.prototype);
ObjectSetPrototypeOf(Stats, StatsBase);

ObjectDefineProperty(Stats.prototype, 'atime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.atimeMs);
ObjectDefineProperty(this, 'atime', { __proto__: null, value });
return this.atime;
},
});

ObjectDefineProperty(Stats.prototype, 'mtime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.mtimeMs);
ObjectDefineProperty(this, 'mtime', { __proto__: null, value });
return this.mtime;
},
});

ObjectDefineProperty(Stats.prototype, 'ctime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.ctimeMs);
ObjectDefineProperty(this, 'ctime', { __proto__: null, value });
return this.ctime;
},
});

ObjectDefineProperty(Stats.prototype, 'birthtime', {
__proto__: null,
enumerable: true,
get: function() {
const value = dateFromMs(this.birthtimeMs);
ObjectDefineProperty(this, 'birthtime', { __proto__: null, value });
return this.birthtime;
},
});

// HACK: Workaround for https://github.com/standard-things/esm/issues/821.
// TODO(ronag): Remove this as soon as `esm` publishes a fixed version.
Stats.prototype.isFile = StatsBase.prototype.isFile;
Expand Down

0 comments on commit 3f648cd

Please sign in to comment.