Skip to content

Commit

Permalink
avoid switch break statements
Browse files Browse the repository at this point in the history
  • Loading branch information
tsctx committed Dec 8, 2023
1 parent fd60bdc commit d634b47
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,22 @@ function consumeEnd (consume) {
const { type, body, resolve, stream, length } = consume

try {
switch (type) {
case 'text':
resolve(chunksDecode(body, length))
break
case 'json':
resolve(JSON.parse(chunksDecode(body, length)))
break
case 'arrayBuffer': {
const dst = new Uint8Array(length)

let pos = 0
for (const buf of body) {
dst.set(buf, pos)
pos += buf.byteLength
}

resolve(dst.buffer)
break
if (type === 'text') {
resolve(chunksDecode(body, length))
} else if (type === 'json') {
resolve(chunksDecode(body, length))
} else if (type === 'arrayBuffer') {
const dst = new Uint8Array(length)

let pos = 0
for (const buf of body) {
dst.set(buf, pos)
pos += buf.byteLength
}
case 'blob':
resolve(new Blob(body, { type: stream[kContentType] }))
break

resolve(dst.buffer)
} else if (type === 'blob') {
resolve(new Blob(body, { type: stream[kContentType] }))
}

consumeFinish(consume)
Expand Down

0 comments on commit d634b47

Please sign in to comment.