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

Function readableAddChunkPushByteMode

lib/internal/streams/readable.js:470–521  ·  view source on GitHub ↗
(stream, state, chunk, encoding)

Source from the content-addressed store, hash-verified

468}
469
470function readableAddChunkPushByteMode(stream, state, chunk, encoding) {
471 if (chunk === null) {
472 state[kState] &= ~kReading;
473 onEofChunk(stream, state);
474 return false;
475 }
476
477 if (typeof chunk === 'string') {
478 encoding ||= state.defaultEncoding;
479 if (state.encoding !== encoding) {
480 chunk = Buffer.from(chunk, encoding);
481 encoding = '';
482 }
483 } else if (chunk instanceof Buffer) {
484 encoding = '';
485 } else if (Stream._isArrayBufferView(chunk)) {
486 chunk = Stream._uint8ArrayToBuffer(chunk);
487 encoding = '';
488 } else if (chunk !== undefined) {
489 errorOrDestroy(stream, new ERR_INVALID_ARG_TYPE(
490 'chunk', ['string', 'Buffer', 'TypedArray', 'DataView'], chunk));
491 return false;
492 }
493
494 if (!chunk || chunk.length <= 0) {
495 state[kState] &= ~kReading;
496 maybeReadMore(stream, state);
497
498 return canPushMore(state);
499 }
500
501 if ((state[kState] & kEnded) !== 0) {
502 errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF());
503 return false;
504 }
505
506 if ((state[kState] & (kDestroyed | kErrored)) !== 0) {
507 return false;
508 }
509
510 state[kState] &= ~kReading;
511 if ((state[kState] & kDecoder) !== 0 && !encoding) {
512 chunk = state[kDecoderValue].write(chunk);
513 if (chunk.length === 0) {
514 maybeReadMore(stream, state);
515 return canPushMore(state);
516 }
517 }
518
519 addChunk(stream, state, chunk, false);
520 return canPushMore(state);
521}
522
523function readableAddChunkPushObjectMode(stream, state, chunk, encoding) {
524 if (chunk === null) {

Callers 1

readable.jsFile · 0.85

Calls 7

onEofChunkFunction · 0.85
errorOrDestroyFunction · 0.85
maybeReadMoreFunction · 0.85
canPushMoreFunction · 0.85
addChunkFunction · 0.85
fromMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…