(stream, state, chunk, encoding)
| 411 | |
| 412 | |
| 413 | function 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 | |
| 448 | function readableAddChunkUnshiftObjectMode(stream, state, chunk) { |
| 449 | if (chunk === null) { |
no test coverage detected
searching dependent graphs…