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.
|
// write() some more.
|
||||||
Readable.prototype.push = function(chunk) {
|
Readable.prototype.push = function(chunk) {
|
||||||
var state = this._readableState;
|
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;
|
state.reading = false;
|
||||||
|
|
||||||
var er = chunkInvalid(state, chunk);
|
var er = chunkInvalid(state, chunk);
|
||||||
|
@ -123,7 +128,10 @@ function readableAddChunk(stream, state, chunk) {
|
||||||
|
|
||||||
// update the buffer info.
|
// update the buffer info.
|
||||||
state.length += state.objectMode ? 1 : chunk.length;
|
state.length += state.objectMode ? 1 : chunk.length;
|
||||||
state.buffer.push(chunk);
|
if (addToFront)
|
||||||
|
state.buffer.unshift(chunk);
|
||||||
|
else
|
||||||
|
state.buffer.push(chunk);
|
||||||
|
|
||||||
if (state.needReadable)
|
if (state.needReadable)
|
||||||
emitReadable(stream);
|
emitReadable(stream);
|
||||||
|
|
Loading…
Reference in New Issue