summaryrefslogtreecommitdiff
path: root/lib/_stream_readable.js
diff options
context:
space:
mode:
authorhimself65 <himself65@outlook.com>2020-04-17 15:04:38 +0800
committerRobert Nagy <ronagy@icloud.com>2020-04-30 11:07:06 +0200
commit0bd24a6e563f92e67f582dbd470355acc74f7792 (patch)
treec0554447221f9762a6257525166e792151c5e79a /lib/_stream_readable.js
parent2496db8e0946de58911cac7b495d854cb18c179d (diff)
downloadnode-new-0bd24a6e563f92e67f582dbd470355acc74f7792.tar.gz
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>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r--lib/_stream_readable.js16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index c4758fb7a9..aac65e9cb3 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -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 = '';