(stream, state, chunk, encoding, addToFront)
| 24339 | }; |
| 24340 | |
| 24341 | function readableAddChunk(stream, state, chunk, encoding, addToFront) { |
| 24342 | var er = chunkInvalid(state, chunk); |
| 24343 | if (er) { |
| 24344 | stream.emit('error', er); |
| 24345 | } else if (chunk === null) { |
| 24346 | state.reading = false; |
| 24347 | onEofChunk(stream, state); |
| 24348 | } else if (state.objectMode || chunk && chunk.length > 0) { |
| 24349 | if (state.ended && !addToFront) { |
| 24350 | var e = new Error('stream.push() after EOF'); |
| 24351 | stream.emit('error', e); |
| 24352 | } else if (state.endEmitted && addToFront) { |
| 24353 | var _e = new Error('stream.unshift() after end event'); |
| 24354 | stream.emit('error', _e); |
| 24355 | } else { |
| 24356 | var skipAdd; |
| 24357 | if (state.decoder && !addToFront && !encoding) { |
| 24358 | chunk = state.decoder.write(chunk); |
| 24359 | skipAdd = !state.objectMode && chunk.length === 0; |
| 24360 | } |
| 24361 | |
| 24362 | if (!addToFront) state.reading = false; |
| 24363 | |
| 24364 | // Don't add to the buffer if we've decoded to an empty string chunk and |
| 24365 | // we're not in object mode |
| 24366 | if (!skipAdd) { |
| 24367 | // if we want the data now, just emit it. |
| 24368 | if (state.flowing && state.length === 0 && !state.sync) { |
| 24369 | stream.emit('data', chunk); |
| 24370 | stream.read(0); |
| 24371 | } else { |
| 24372 | // update the buffer info. |
| 24373 | state.length += state.objectMode ? 1 : chunk.length; |
| 24374 | if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); |
| 24375 | |
| 24376 | if (state.needReadable) emitReadable(stream); |
| 24377 | } |
| 24378 | } |
| 24379 | |
| 24380 | maybeReadMore(stream, state); |
| 24381 | } |
| 24382 | } else if (!addToFront) { |
| 24383 | state.reading = false; |
| 24384 | } |
| 24385 | |
| 24386 | return needMoreData(state); |
| 24387 | } |
| 24388 | |
| 24389 | // if it's past the high water mark, we can push in some more. |
| 24390 | // Also, if we have no data yet, we can stand some |
no test coverage detected