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

Method readdirSync

lib/internal/vfs/providers/memory.js:569–603  ·  view source on GitHub ↗
(path, options)

Source from the content-addressed store, hash-verified

567 }
568
569 readdirSync(path, options) {
570 const entry = this.#getEntry(path, 'scandir', true);
571 if (!entry.isDirectory()) {
572 throw createENOTDIR('scandir', path);
573 }
574
575 // Ensure directory is populated (for lazy population)
576 this.#ensurePopulated(entry, path);
577
578 const normalized = this.#normalizePath(path);
579 const withFileTypes = options?.withFileTypes === true;
580 const recursive = options?.recursive === true;
581
582 if (recursive) {
583 return this.#readdirRecursive(entry, normalized, withFileTypes);
584 }
585
586 if (withFileTypes) {
587 const dirents = [];
588 for (const { 0: name, 1: childEntry } of entry.children) {
589 let type;
590 if (childEntry.isSymbolicLink()) {
591 type = UV_DIRENT_LINK;
592 } else if (childEntry.isDirectory()) {
593 type = UV_DIRENT_DIR;
594 } else {
595 type = UV_DIRENT_FILE;
596 }
597 ArrayPrototypePush(dirents, new Dirent(name, type, normalized));
598 }
599 return dirents;
600 }
601
602 return ArrayFrom(entry.children.keys());
603 }
604
605 /**
606 * Recursively reads directory contents.

Callers 1

readdirMethod · 0.95

Calls 8

#getEntryMethod · 0.95
#ensurePopulatedMethod · 0.95
#normalizePathMethod · 0.95
#readdirRecursiveMethod · 0.95
createENOTDIRFunction · 0.85
keysMethod · 0.65
isDirectoryMethod · 0.45
isSymbolicLinkMethod · 0.45

Tested by

no test coverage detected