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

Function readableAddChunkUnshiftByteMode

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

Source from the content-addressed store, hash-verified

411
412
413function readableAddChunkUnshiftByteMode(stream, state, chunk, encoding) {
414 if (chunk === null) {
415 state[kState] &= ~kReading;
416 onEofChunk(stream, state);
417
418 return false;
419 }
420
421 if (typeof chunk === 'string') {
422 encoding ||= state.defaultEncoding;
423 if (state.encoding !== encoding) {
424 if (state.encoding) {
425 // When unshifting, if state.encoding is set, we have to save
426 // the string in the BufferList with the state encoding.
427 chunk = Buffer.from(chunk, encoding).toString(state.encoding);
428 } else {
429 chunk = Buffer.from(chunk, encoding);
430 }
431 }
432 } else if (Stream._isArrayBufferView(chunk)) {
433 chunk = Stream._uint8ArrayToBuffer(chunk);
434 } else if (chunk !== undefined && !(chunk instanceof Buffer)) {
435 errorOrDestroy(stream, new ERR_INVALID_ARG_TYPE(
436 'chunk', ['string', 'Buffer', 'TypedArray', 'DataView'], chunk));
437 return false;
438 }
439
440
441 if (!(chunk && chunk.length > 0)) {
442 return canPushMore(state);
443 }
444
445 return readableAddChunkUnshiftValue(stream, state, chunk);
446}
447
448function readableAddChunkUnshiftObjectMode(stream, state, chunk) {
449 if (chunk === null) {

Callers 1

readable.jsFile · 0.85

Calls 6

onEofChunkFunction · 0.85
errorOrDestroyFunction · 0.85
canPushMoreFunction · 0.85
toStringMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…