Skip to content

Commit 4cfa7e0

Browse files
himself65targos
authored andcommitted
stream: simplify Readable push/unshift logic
PR-URL: #32899 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 5eccf1e commit 4cfa7e0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/_stream_readable.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,15 @@ function readableAddChunk(stream, chunk, encoding, addToFront) {
230230
if (!state.objectMode) {
231231
if (typeof chunk === 'string') {
232232
encoding = encoding || state.defaultEncoding;
233-
if (addToFront && state.encoding && state.encoding !== encoding) {
234-
// When unshifting, if state.encoding is set, we have to save
235-
// the string in the BufferList with the state encoding.
236-
chunk = Buffer.from(chunk, encoding).toString(state.encoding);
237-
} else if (encoding !== state.encoding) {
238-
chunk = Buffer.from(chunk, encoding);
239-
encoding = '';
233+
if (state.encoding !== encoding) {
234+
if (addToFront && state.encoding) {
235+
// When unshifting, if state.encoding is set, we have to save
236+
// the string in the BufferList with the state encoding.
237+
chunk = Buffer.from(chunk, encoding).toString(state.encoding);
238+
} else {
239+
chunk = Buffer.from(chunk, encoding);
240+
encoding = '';
241+
}
240242
}
241243
} else if (chunk instanceof Buffer) {
242244
encoding = '';

0 commit comments

Comments
 (0)