* @param {AsyncIterable|ReadableStream|Readable} stream * @returns {Promise }
(stream)
| 64 | * @returns {Promise<string>} |
| 65 | */ |
| 66 | async function text(stream) { |
| 67 | const dec = new TextDecoder(); |
| 68 | let str = ''; |
| 69 | for await (const chunk of stream) { |
| 70 | if (typeof chunk === 'string') |
| 71 | str += chunk; |
| 72 | else |
| 73 | str += dec.decode(chunk, { stream: true }); |
| 74 | } |
| 75 | // Flush the streaming TextDecoder so that any pending |
| 76 | // incomplete multibyte characters are handled. |
| 77 | str += dec.decode(undefined, { stream: false }); |
| 78 | return str; |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @param {AsyncIterable|ReadableStream|Readable} stream |