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 2a995e3
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* istanbul ignore file: TODO add more coverage */

// Ported from https://github.com/nodejs/undici/pull/907

'use strict'
Expand Down Expand Up @@ -182,7 +180,7 @@ async function consume (stream, type) {
resolve,
reject,
length: 0,
body: undefined
body: type === kTextType || type === kJSONType ? '' : []
}

stream
Expand Down Expand Up @@ -255,28 +253,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 2a995e3

Please sign in to comment.