| 370 | } |
| 371 | |
| 372 | const decodeLine = (bytes: Uint8Array, out: Array<unknown>, unterminated: boolean) => { |
| 373 | let line: string |
| 374 | try { |
| 375 | line = decoder.decode(bytes) |
| 376 | } catch (cause) { |
| 377 | return new NdjsonError({ kind: "Unpack", reason: "InvalidUtf8", unterminated, cause }) |
| 378 | } |
| 379 | const firstLine = decoder !== utf8Decoder |
| 380 | decoder = utf8Decoder |
| 381 | // A stripped BOM alone is not an unterminated record. |
| 382 | if (firstLine && unterminated && line.length === 0) return |
| 383 | return parseLine(line, out, ignoreEmptyLines, unterminated) |
| 384 | } |
| 385 | |
| 386 | const step: DecodeStep<Arr.NonEmptyReadonlyArray<Uint8Array>> = (chunks, out) => { |
| 387 | for (const chunk of chunks) { |