Skip to content

Commit

Permalink
fixup: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Jul 30, 2021
1 parent 8d348e8 commit d50ed00
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async function consume (stream, type) {
resolve,
reject,
length: 0,
body: undefined
body: type === kTextType || type === kJSONType ? '' : []
}

stream
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d50ed00

Please sign in to comment.