MCPcopy Index your code
hub / github.com/nodejs/node / #readImpl

Method #readImpl

lib/internal/fs/dir.js:114–180  ·  view source on GitHub ↗
(maybeSync, callback)

Source from the content-addressed store, hash-verified

112 }
113
114 #readImpl(maybeSync, callback) {
115 if (this.#closed === true) {
116 throw new ERR_DIR_CLOSED();
117 }
118
119 if (callback === undefined) {
120 return this.#readPromisified();
121 }
122
123 validateFunction(callback, 'callback');
124
125 if (this.#operationQueue !== null) {
126 ArrayPrototypePush(this.#operationQueue, () => {
127 this.#readImpl(maybeSync, callback);
128 });
129 return;
130 }
131
132 if (this.#processHandlerQueue()) {
133 try {
134 const dirent = ArrayPrototypeShift(this.#bufferedEntries);
135
136 if (this.#options.recursive && dirent.isDirectory()) {
137 this.#readSyncRecursive(dirent);
138 }
139
140 if (maybeSync)
141 process.nextTick(callback, null, dirent);
142 else
143 callback(null, dirent);
144 return;
145 } catch (error) {
146 return callback(error);
147 }
148 }
149
150 const req = new FSReqCallback();
151 req.oncomplete = (err, result) => {
152 process.nextTick(() => {
153 const queue = this.#operationQueue;
154 this.#operationQueue = null;
155 for (const op of queue) op();
156 });
157
158 if (err || result === null) {
159 return callback(err, result);
160 }
161
162 try {
163 this.#processReadResult(this.#path, result);
164 const dirent = ArrayPrototypeShift(this.#bufferedEntries);
165 if (this.#options.recursive && dirent.isDirectory()) {
166 this.#readSyncRecursive(dirent);
167 }
168 callback(null, dirent);
169 } catch (error) {
170 callback(error);
171 }

Callers 1

readMethod · 0.95

Calls 7

#processHandlerQueueMethod · 0.95
#readSyncRecursiveMethod · 0.95
#processReadResultMethod · 0.95
callbackFunction · 0.50
opFunction · 0.50
isDirectoryMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected