(chunks, out)
| 384 | } |
| 385 | |
| 386 | const step: DecodeStep<Arr.NonEmptyReadonlyArray<Uint8Array>> = (chunks, out) => { |
| 387 | for (const chunk of chunks) { |
| 388 | let start = 0 |
| 389 | for (let i = 0; i < chunk.length; i++) { |
| 390 | const byte = chunk[i] |
| 391 | if (byte === LF || byte === CR) { |
| 392 | if (byte === LF && afterCR) { |
| 393 | start = i + 1 |
| 394 | } else { |
| 395 | const error = decodeLine(takeLine(chunk, start, i), out, false) |
| 396 | if (error !== undefined) return error |
| 397 | start = i + 1 |
| 398 | } |
| 399 | afterCR = byte === CR |
| 400 | } else { |
| 401 | afterCR = false |
| 402 | if (pendingBytes + i + 1 - start > maxLineBytes) { |
| 403 | return new NdjsonError({ |
| 404 | kind: "Unpack", |
| 405 | reason: "LineTooLarge", |
| 406 | unterminated: false, |
| 407 | cause: new RangeError(`NDJSON line exceeds maxLineBytes of ${maxLineBytes}`) |
| 408 | }) |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | if (start < chunk.length) { |
| 413 | // Copy, so a reused upstream buffer cannot change the line |
| 414 | pending.push(chunk.slice(start)) |
| 415 | pendingBytes += chunk.length - start |
| 416 | } |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | const flush = (out: Array<unknown>) => |
| 421 | pendingBytes === 0 ? undefined : decodeLine(takeLine(emptyBytes, 0, 0), out, true) |
no test coverage detected