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

Function addChunk

lib/internal/streams/readable.js:557–586  ·  view source on GitHub ↗
(stream, state, chunk, addToFront)

Source from the content-addressed store, hash-verified

555}
556
557function addChunk(stream, state, chunk, addToFront) {
558 if ((state[kState] & (kFlowing | kSync | kDataListening)) === (kFlowing | kDataListening) && state.length === 0) {
559 // Use the guard to avoid creating `Set()` repeatedly
560 // when we have multiple pipes.
561 if ((state[kState] & kMultiAwaitDrain) !== 0) {
562 state.awaitDrainWriters.clear();
563 } else {
564 state.awaitDrainWriters = null;
565 }
566
567 state[kState] |= kDataEmitted;
568 stream.emit('data', chunk);
569 } else {
570 // Update the buffer info.
571 state.length += (state[kState] & kObjectMode) !== 0 ? 1 : chunk.length;
572 if (addToFront) {
573 if (state.bufferIndex > 0) {
574 state.buffer[--state.bufferIndex] = chunk;
575 } else {
576 state.buffer.unshift(chunk); // Slow path
577 }
578 } else {
579 state.buffer.push(chunk);
580 }
581
582 if ((state[kState] & kNeedReadable) !== 0)
583 emitReadable(stream);
584 }
585 maybeReadMore(stream, state);
586}
587
588Readable.prototype.isPaused = function() {
589 const state = this._readableState;

Calls 6

emitReadableFunction · 0.85
maybeReadMoreFunction · 0.85
unshiftMethod · 0.80
clearMethod · 0.65
emitMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…