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

Function onEofChunk

lib/internal/streams/readable.js:802–828  ·  view source on GitHub ↗
(stream, state)

Source from the content-addressed store, hash-verified

800};
801
802function onEofChunk(stream, state) {
803 debug('onEofChunk');
804 if ((state[kState] & kEnded) !== 0) return;
805 const decoder = (state[kState] & kDecoder) !== 0 ? state[kDecoderValue] : null;
806 if (decoder) {
807 const chunk = decoder.end();
808 if (chunk?.length) {
809 state.buffer.push(chunk);
810 state.length += (state[kState] & kObjectMode) !== 0 ? 1 : chunk.length;
811 }
812 }
813 state[kState] |= kEnded;
814
815 if ((state[kState] & kSync) !== 0) {
816 // If we are sync, wait until next tick to emit the data.
817 // Otherwise we risk emitting data in the flow()
818 // the readable code triggers during a read() call.
819 emitReadable(stream);
820 } else {
821 // Emit 'readable' now to make sure it gets picked up.
822 state[kState] &= ~kNeedReadable;
823 state[kState] |= kEmittedReadable;
824 // We have to emit readable now that we are EOF. Modules
825 // in the ecosystem (e.g. dicer) rely on this event being sync.
826 emitReadable_(stream);
827 }
828}
829
830// Don't emit readable right away in sync mode, because this can trigger
831// another read() call => stack overflow. This way, it might trigger

Calls 5

emitReadableFunction · 0.85
emitReadable_Function · 0.85
debugFunction · 0.50
endMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected