* Generates a Stream from a newline-separated ReadableStream * where each item is a JSON value.
(readableStream, controller)
| 69125 | } |
| 69126 | } |
| 69127 | return new _Stream(iterator2, controller); |
| 69128 | } |
| 69129 | /** |
| 69130 | * Generates a Stream from a newline-separated ReadableStream |
| 69131 | * where each item is a JSON value. |
| 69132 | */ |
| 69133 | static fromReadableStream(readableStream, controller) { |
| 69134 | let consumed = false; |
| 69135 | async function* iterLines() { |
| 69136 | const lineDecoder = new LineDecoder(); |
| 69137 | const iter = readableStreamAsyncIterable(readableStream); |
| 69138 | for await (const chunk of iter) { |
| 69139 | for (const line of lineDecoder.decode(chunk)) { |
| 69140 | yield line; |
| 69141 | } |
| 69142 | } |
| 69143 | for (const line of lineDecoder.flush()) { |
| 69144 | yield line; |
| 69145 | } |
| 69146 | } |
| 69147 | async function* iterator2() { |
| 69148 | if (consumed) { |
| 69149 | throw new Error("Cannot iterate over a consumed stream, use `.tee()` to split the stream."); |
| 69150 | } |
| 69151 | consumed = true; |
| 69152 | let done = false; |
| 69153 | try { |
| 69154 | for await (const line of iterLines()) { |
| 69155 | if (done) |
| 69156 | continue; |
| 69157 | if (line) |
| 69158 | yield JSON.parse(line); |
| 69159 | } |
| 69160 | done = true; |
| 69161 | } catch (e3) { |
| 69162 | if (e3 instanceof Error && e3.name === "AbortError") |
| 69163 | return; |
| 69164 | throw e3; |
| 69165 | } finally { |
| 69166 | if (!done) |
| 69167 | controller.abort(); |
| 69168 | } |
no outgoing calls
no test coverage detected