mirror of https://github.com/nodejs/node.git
stream: Add stream.unshift(chunk)
parent
7764b84297
commit
4b67f0be6d
|
@ -106,10 +106,15 @@ function Readable(options) {
|
|||
// write() some more.
|
||||
Readable.prototype.push = function(chunk) {
|
||||
var state = this._readableState;
|
||||
return readableAddChunk(this, state, chunk);
|
||||
return readableAddChunk(this, state, chunk, false);
|
||||
};
|
||||
|
||||
function readableAddChunk(stream, state, chunk) {
|
||||
Readable.prototype.unshift = function(chunk) {
|
||||
var state = this._readableState;
|
||||
return readableAddChunk(this, state, chunk, true);
|
||||
};
|
||||
|
||||
function readableAddChunk(stream, state, chunk, addToFront) {
|
||||
state.reading = false;
|
||||
|
||||
var er = chunkInvalid(state, chunk);
|
||||
|
@ -123,6 +128,9 @@ function readableAddChunk(stream, state, chunk) {
|
|||
|
||||
// update the buffer info.
|
||||
state.length += state.objectMode ? 1 : chunk.length;
|
||||
if (addToFront)
|
||||
state.buffer.unshift(chunk);
|
||||
else
|
||||
state.buffer.push(chunk);
|
||||
|
||||
if (state.needReadable)
|
||||
|
|
Loading…
Reference in New Issue