( s: LoadState, buf: Buffer, boundaryMarker: Buffer, )
| 612 | |
| 613 | // Strip attr-snaps, truncate on boundaries. Kept lines write as runs. |
| 614 | function scanChunkLines( |
| 615 | s: LoadState, |
| 616 | buf: Buffer, |
| 617 | boundaryMarker: Buffer, |
| 618 | ): { lastSnapStart: number; lastSnapEnd: number; trailStart: number } { |
| 619 | let boundaryAt = buf.indexOf(boundaryMarker) |
| 620 | let runStart = 0 |
| 621 | let lineStart = 0 |
| 622 | let lastSnapStart = -1 |
| 623 | let lastSnapEnd = -1 |
| 624 | let nl = buf.indexOf(LF) |
| 625 | while (nl !== -1) { |
| 626 | const lineEnd = nl + 1 |
| 627 | if (boundaryAt !== -1 && boundaryAt < lineStart) { |
| 628 | boundaryAt = buf.indexOf(boundaryMarker, lineStart) |
| 629 | } |
| 630 | if (hasPrefix(buf, ATTR_SNAP_PREFIX, lineStart, lineEnd)) { |
| 631 | sinkWrite(s.out, buf, runStart, lineStart) |
| 632 | lastSnapStart = lineStart |
| 633 | lastSnapEnd = lineEnd |
| 634 | runStart = lineEnd |
| 635 | } else if ( |
| 636 | boundaryAt >= lineStart && |
| 637 | boundaryAt < Math.min(lineStart + BOUNDARY_SEARCH_BOUND, lineEnd) |
| 638 | ) { |
| 639 | const hit = parseBoundaryLine(buf.toString('utf-8', lineStart, nl)) |
| 640 | if (hit?.hasPreservedSegment) { |
| 641 | s.hasPreservedSegment = true // don't truncate; preserved msgs already in output |
| 642 | } else if (hit) { |
| 643 | s.out.len = 0 |
| 644 | s.boundaryStartOffset = s.bufFileOff + lineStart |
| 645 | s.hasPreservedSegment = false |
| 646 | s.lastSnapSrc = null |
| 647 | lastSnapStart = -1 |
| 648 | s.straddleSnapCarryLen = 0 |
| 649 | runStart = lineStart |
| 650 | } |
| 651 | boundaryAt = buf.indexOf( |
| 652 | boundaryMarker, |
| 653 | boundaryAt + boundaryMarker.length, |
| 654 | ) |
| 655 | } |
| 656 | lineStart = lineEnd |
| 657 | nl = buf.indexOf(LF, lineStart) |
| 658 | } |
| 659 | sinkWrite(s.out, buf, runStart, lineStart) |
| 660 | return { lastSnapStart, lastSnapEnd, trailStart: lineStart } |
| 661 | } |
| 662 | |
| 663 | // In-buf snap wins over straddle (later in file). carryBuf still valid here. |
| 664 | function captureSnap( |
no test coverage detected