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

Function createVfsHandlers

lib/internal/vfs/setup.js:178–656  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

176}
177
178function createVfsHandlers() {
179 return {
180 __proto__: null,
181
182 // ==================== Sync path-based read ops ====================
183
184 existsSync(path) {
185 const pathStr = toPathStr(path);
186 if (pathStr === null) return undefined;
187 const r = findVFSForExists(pathStr);
188 return r !== null ? r.exists : undefined;
189 },
190 readFileSync(path, options) {
191 if (typeof path === 'number') {
192 const vfd = getVirtualFd(path);
193 if (vfd) {
194 const enc = typeof options === 'string' ? options : options?.encoding;
195 if (enc && enc !== 'buffer') assertEncoding(enc);
196 return vfd.entry.readFileSync(options);
197 }
198 return undefined;
199 }
200 const pathStr = toPathStr(path);
201 if (pathStr === null) return undefined;
202 const enc = typeof options === 'string' ? options : options?.encoding;
203 if (enc && enc !== 'buffer') assertEncoding(enc);
204 return findVFSWith(pathStr, 'open', (vfs, n) => vfs.readFileSync(n, options));
205 },
206 readdirSync(path, options) {
207 const result = vfsRead(path, 'scandir', (vfs, n) => vfs.readdirSync(n, options));
208 if (result !== undefined && options?.encoding === 'buffer' && !options?.withFileTypes) {
209 for (let i = 0; i < result.length; i++) {
210 if (typeof result[i] === 'string') result[i] = Buffer.from(result[i]);
211 }
212 }
213 return result;
214 },
215 lstatSync(path, options) {
216 const pathStr = toPathStr(path);
217 if (pathStr === null) return undefined;
218 const normalized = resolve(pathStr);
219 for (let i = 0; i < activeVFSList.length; i++) {
220 const vfs = activeVFSList[i];
221 if (vfs.shouldHandle(normalized)) {
222 try {
223 return vfs.lstatSync(normalized, options);
224 } catch (e) {
225 if (e?.code === 'ENOENT' && options?.throwIfNoEntry === false) return undefined;
226 throw e;
227 }
228 }
229 }
230 return undefined;
231 },
232 statSync(path, options) {
233 try {
234 return vfsRead(path, 'stat', (vfs, n) => vfs.statSync(n, options));
235 } catch (err) {

Callers 1

registerVFSFunction · 0.85

Calls 15

vfsOpVoidFunction · 0.85
vfsOpFunction · 0.85
rmSyncMethod · 0.80
opendirSyncMethod · 0.80
lchownMethod · 0.80
lutimesMethod · 0.80
lchmodMethod · 0.80
writeFileSyncMethod · 0.45
appendFileSyncMethod · 0.45
mkdirSyncMethod · 0.45
rmdirSyncMethod · 0.45
unlinkSyncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…