(buf: Buffer)
| 127 | } |
| 128 | |
| 129 | function parseJSONLBuffer<T>(buf: Buffer): T[] { |
| 130 | const bufLen = buf.length |
| 131 | let start = 0 |
| 132 | |
| 133 | // Strip UTF-8 BOM (EF BB BF) |
| 134 | if (buf[0] === 0xef && buf[1] === 0xbb && buf[2] === 0xbf) { |
| 135 | start = 3 |
| 136 | } |
| 137 | |
| 138 | const results: T[] = [] |
| 139 | while (start < bufLen) { |
| 140 | let end = buf.indexOf(0x0a, start) |
| 141 | if (end === -1) end = bufLen |
| 142 | |
| 143 | const line = buf.toString('utf8', start, end).trim() |
| 144 | start = end + 1 |
| 145 | if (!line) continue |
| 146 | try { |
| 147 | results.push(JSON.parse(line) as T) |
| 148 | } catch { |
| 149 | // Skip malformed lines |
| 150 | } |
| 151 | } |
| 152 | return results |
| 153 | } |
| 154 | |
| 155 | function parseJSONLString<T>(data: string): T[] { |
| 156 | const stripped = stripBOM(data) |
no test coverage detected