From d50ed00eea0de74e104e7f3cfb6c37f6ca977fe7 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Fri, 30 Jul 2021 15:23:31 +0200 Subject: [PATCH] fixup: simplify --- lib/api/readable.js | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/api/readable.js b/lib/api/readable.js index 26805e150b7..45bd9e15dda 100644 --- a/lib/api/readable.js +++ b/lib/api/readable.js @@ -182,7 +182,7 @@ async function consume (stream, type) { resolve, reject, length: 0, - body: undefined + body: type === kTextType || type === kJSONType ? '' : [] } stream @@ -255,28 +255,13 @@ function consumeEnd (consume) { } } -function consumePush (consume, chunk, encoding) { +function consumePush (consume, chunk) { + consume.length += chunk.length if (consume.type === kTextType || consume.type === kJSONType) { - consumePushString(consume, chunk, encoding) + consume.body += chunk } else { - consumePushBuffer(consume, chunk, encoding) - } -} - -function consumePushString (consume, chunk, encoding) { - if (!consume.body) { - consume.body = '' - } - consume.length += chunk.length - consume.body += chunk -} - -function consumePushBuffer (consume, chunk, encoding) { - if (!consume.body) { - consume.body = [] + consume.body.push(chunk) } - consume.length += chunk.byteLength - consume.body.push(chunk) } function consumeFinish (consume, err) {