* @param {Consume} consume * @param {BufferEncoding} encoding * @returns {void}
(consume, encoding)
| 519 | * @returns {void} |
| 520 | */ |
| 521 | function consumeEnd (consume, encoding) { |
| 522 | const { type, body, resolve, stream, length } = consume |
| 523 | |
| 524 | try { |
| 525 | if (type === 'text') { |
| 526 | resolve(chunksDecode(body, length, encoding)) |
| 527 | } else if (type === 'json') { |
| 528 | resolve(JSON.parse(chunksDecode(body, length, encoding))) |
| 529 | } else if (type === 'arrayBuffer') { |
| 530 | resolve(chunksConcat(body, length).buffer) |
| 531 | } else if (type === 'blob') { |
| 532 | resolve(new Blob(body, { type: stream[kContentType] })) |
| 533 | } else if (type === 'bytes') { |
| 534 | resolve(chunksConcat(body, length)) |
| 535 | } |
| 536 | |
| 537 | consumeFinish(consume) |
| 538 | } catch (err) { |
| 539 | stream.destroy(err) |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * @param {Consume} consume |
no test coverage detected