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

Method read

lib/internal/fs/read/context.js:135–178  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

133 }
134
135 read() {
136 let buffer;
137 let offset;
138 let length;
139
140 if (this.signal?.aborted) {
141 return this.close(
142 new AbortError(undefined, { cause: this.signal.reason }));
143 }
144
145 if (this.userBuffer) {
146 if (this.size === 0) {
147 buffer = this.buffer;
148 offset = this.pos;
149 length = this.buffer.byteLength - this.pos;
150
151 if (length === 0) {
152 buffer = this.overflowBuffer ??= Buffer.allocUnsafeSlow(1);
153 offset = 0;
154 length = 1;
155 this.checkOverflow = true;
156 }
157 } else {
158 buffer = this.buffer;
159 offset = this.pos;
160 length = MathMin(kReadFileBufferLength, this.size - this.pos);
161 }
162 } else if (this.size === 0) {
163 buffer = Buffer.allocUnsafeSlow(kReadFileUnknownBufferLength);
164 offset = 0;
165 length = kReadFileUnknownBufferLength;
166 this.buffer = buffer;
167 } else {
168 buffer = this.buffer;
169 offset = this.pos;
170 length = MathMin(kReadFileBufferLength, this.size - this.pos);
171 }
172
173 const req = new FSReqCallback();
174 req.oncomplete = readFileAfterRead;
175 req.context = this;
176
177 read(this.fd, buffer, offset, length, -1, req);
178 }
179
180 close(err) {
181 if (this.isUserFd) {

Callers 1

readFileAfterReadFunction · 0.45

Calls 2

closeMethod · 0.95
readFunction · 0.50

Tested by

no test coverage detected