MCPcopy Index your code
hub / github.com/nodejs/node / createFileStats

Function createFileStats

lib/internal/vfs/stats.js:95–140  ·  view source on GitHub ↗

* Creates a Stats object for a virtual file. * @param {number} size The file size in bytes * @param {object} [options] Optional stat properties * @param {number} [options.mode] File mode (default: 0o644) * @param {number} [options.uid] User ID (default: process.getuid() or 0) * @param {number}

(size, options = kEmptyObject)

Source from the content-addressed store, hash-verified

93 * @returns {Stats}
94 */
95function createFileStats(size, options = kEmptyObject) {
96 const now = DateNow();
97 const mode = (options.mode ?? 0o644) | S_IFREG;
98 const nlink = options.nlink ?? 1;
99 const uid = options.uid ?? (process.getuid?.() ?? 0);
100 const gid = options.gid ?? (process.getgid?.() ?? 0);
101 const atimeMs = options.atimeMs ?? now;
102 const mtimeMs = options.mtimeMs ?? now;
103 const ctimeMs = options.ctimeMs ?? now;
104 const birthtimeMs = options.birthtimeMs ?? now;
105 const blocks = MathCeil(size / 512);
106 const ino = inoCounter++;
107
108 const atime = msToTimeSpec(atimeMs);
109 const mtime = msToTimeSpec(mtimeMs);
110 const ctime = msToTimeSpec(ctimeMs);
111 const birthtime = msToTimeSpec(birthtimeMs);
112
113 if (options.bigint) {
114 return fillBigIntStatsArray(
115 kVfsDev, mode, nlink, uid, gid, 0, kDefaultBlockSize, ino,
116 size, blocks, atime, mtime, ctime, birthtime,
117 );
118 }
119
120 statsArray[0] = kVfsDev; // dev
121 statsArray[1] = mode; // mode
122 statsArray[2] = nlink; // nlink
123 statsArray[3] = uid; // uid
124 statsArray[4] = gid; // gid
125 statsArray[5] = 0; // rdev
126 statsArray[6] = kDefaultBlockSize; // blksize
127 statsArray[7] = ino; // ino
128 statsArray[8] = size; // size
129 statsArray[9] = blocks; // blocks
130 statsArray[10] = atime.sec; // atime_sec
131 statsArray[11] = atime.nsec; // atime_nsec
132 statsArray[12] = mtime.sec; // mtime_sec
133 statsArray[13] = mtime.nsec; // mtime_nsec
134 statsArray[14] = ctime.sec; // ctime_sec
135 statsArray[15] = ctime.nsec; // ctime_nsec
136 statsArray[16] = birthtime.sec; // birthtime_sec
137 statsArray[17] = birthtime.nsec; // birthtime_nsec
138
139 return getStatsFromBinding(statsArray);
140}
141
142/**
143 * Creates a Stats object for a virtual directory.

Callers 2

#createStatsMethod · 0.85

Calls 3

msToTimeSpecFunction · 0.85
fillBigIntStatsArrayFunction · 0.85
getStatsFromBindingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…