(response: Response)
| 150 | } |
| 151 | |
| 152 | export async function* streamJSON(response: Response): AsyncGenerator<any> { |
| 153 | let buffer = ""; |
| 154 | for await (const value of streamResponse(response)) { |
| 155 | buffer += value; |
| 156 | |
| 157 | let position; |
| 158 | while ((position = buffer.indexOf("\n")) >= 0) { |
| 159 | const line = buffer.slice(0, position); |
| 160 | try { |
| 161 | const data = JSON.parse(line); |
| 162 | yield data; |
| 163 | } catch (e) { |
| 164 | throw new Error(`Malformed JSON sent from server: ${line}`); |
| 165 | } |
| 166 | buffer = buffer.slice(position + 1); |
| 167 | } |
| 168 | } |
| 169 | } |
no test coverage detected