(chunk, controller)
| 33 | function parseNDJSON() { |
| 34 | return new TransformStream({ |
| 35 | transform(chunk, controller) { |
| 36 | for (const item of chunk.split('\n')) { |
| 37 | if (!item.length) continue |
| 38 | try { |
| 39 | controller.enqueue(JSON.parse(item)) |
| 40 | } catch (error) { |
| 41 | // this exception is a common problem that we won't handle in this class: |
| 42 | // if the arrived data is not completed, it should be stored in memory |
| 43 | // until completed |
| 44 | // 1st msg received - {"name": "er" |
| 45 | // 2st msg received - "ick"}\n |
| 46 | // result {"name": "erick"}\n |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | }) |
| 51 | } |
| 52 | let counter = 0 |
nothing calls this directly
no outgoing calls
no test coverage detected