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

Function onStreamRead

lib/internal/stream_base_commons.js:166–234  ·  view source on GitHub ↗
(arrayBuffer)

Source from the content-addressed store, hash-verified

164}
165
166function onStreamRead(arrayBuffer) {
167 const nread = streamBaseState[kReadBytesOrError];
168
169 const handle = this;
170 const stream = this[owner_symbol];
171
172 stream[kUpdateTimer]();
173
174 if (nread > 0 && !stream.destroyed) {
175 let ret;
176 let result;
177 const userBuf = stream[kBuffer];
178 if (userBuf) {
179 result = (stream[kBufferCb](nread, userBuf) !== false);
180 const bufGen = stream[kBufferGen];
181 if (bufGen !== null) {
182 const nextBuf = bufGen();
183 if (isUint8Array(nextBuf))
184 stream[kBuffer] = ret = nextBuf;
185 }
186 } else {
187 const offset = streamBaseState[kArrayBufferOffset];
188 const buf = new FastBuffer(arrayBuffer, offset, nread);
189 result = stream.push(buf);
190 }
191 if (!result) {
192 handle.reading = false;
193 if (!stream.destroyed) {
194 const err = handle.readStop();
195 if (err)
196 stream.destroy(new ErrnoException(err, 'read'));
197 }
198 }
199
200 return ret;
201 }
202
203 if (nread === 0) {
204 return;
205 }
206
207 // After seeing EOF, most streams will be closed permanently,
208 // and will not deliver any more read events after this point.
209 // (equivalently, it should have called readStop on itself already).
210 // Some streams may be reset and explicitly started again with a call
211 // to readStart, such as TTY.
212
213 if (nread !== UV_EOF) {
214 // CallJSOnreadMethod expects the return value to be a buffer.
215 // Ref: https://github.com/nodejs/node/pull/34375
216 stream.destroy(new ErrnoException(nread, 'read'));
217 return;
218 }
219
220 // Defer this until we actually emit end
221 if (stream._readableState.endEmitted) {
222 if (stream[kMaybeDestroy])
223 stream[kMaybeDestroy]();

Callers

nothing calls this directly

Calls 6

isUint8ArrayFunction · 0.85
pushMethod · 0.45
readStopMethod · 0.45
destroyMethod · 0.45
onMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…