mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
stream: simplify Readable push/unshift logic
PR-URL: https://github.com/nodejs/node/pull/32899 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
@@ -233,13 +233,15 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
|
||||
if (!state.objectMode) {
|
||||
if (typeof chunk === 'string') {
|
||||
encoding = encoding || state.defaultEncoding;
|
||||
if (addToFront && state.encoding && state.encoding !== encoding) {
|
||||
// When unshifting, if state.encoding is set, we have to save
|
||||
// the string in the BufferList with the state encoding.
|
||||
chunk = Buffer.from(chunk, encoding).toString(state.encoding);
|
||||
} else if (encoding !== state.encoding) {
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
encoding = '';
|
||||
if (state.encoding !== encoding) {
|
||||
if (addToFront && state.encoding) {
|
||||
// When unshifting, if state.encoding is set, we have to save
|
||||
// the string in the BufferList with the state encoding.
|
||||
chunk = Buffer.from(chunk, encoding).toString(state.encoding);
|
||||
} else {
|
||||
chunk = Buffer.from(chunk, encoding);
|
||||
encoding = '';
|
||||
}
|
||||
}
|
||||
} else if (chunk instanceof Buffer) {
|
||||
encoding = '';
|
||||
|
||||
Reference in New Issue
Block a user