MCPcopy Index your code
hub / github.com/claude-code-best/claude-code / processStraddle

Function processStraddle

src/utils/sessionStoragePortable.ts:570–609  ·  view source on GitHub ↗
(
  s: LoadState,
  chunk: Buffer,
  bytesRead: number,
)

Source from the content-addressed store, hash-verified

568
569// Line spanning the chunk seam. 0 = fall through to concat.
570function processStraddle(
571 s: LoadState,
572 chunk: Buffer,
573 bytesRead: number,
574): number {
575 s.straddleSnapCarryLen = 0
576 s.straddleSnapTailEnd = 0
577 if (s.carryLen === 0) return 0
578 const cb = s.carryBuf!
579 const firstNl = chunk.indexOf(LF)
580 if (firstNl === -1 || firstNl >= bytesRead) return 0
581 const tailEnd = firstNl + 1
582 if (hasPrefix(cb, ATTR_SNAP_PREFIX, 0, s.carryLen)) {
583 s.straddleSnapCarryLen = s.carryLen
584 s.straddleSnapTailEnd = tailEnd
585 s.lastSnapSrc = null
586 } else if (s.carryLen < ATTR_SNAP_PREFIX.length) {
587 return 0 // too short to rule out attr-snap
588 } else {
589 if (hasPrefix(cb, SYSTEM_PREFIX, 0, s.carryLen)) {
590 const hit = parseBoundaryLine(
591 cb.toString('utf-8', 0, s.carryLen) +
592 chunk.toString('utf-8', 0, firstNl),
593 )
594 if (hit?.hasPreservedSegment) {
595 s.hasPreservedSegment = true
596 } else if (hit) {
597 s.out.len = 0
598 s.boundaryStartOffset = s.bufFileOff
599 s.hasPreservedSegment = false
600 s.lastSnapSrc = null
601 }
602 }
603 sinkWrite(s.out, cb, 0, s.carryLen)
604 sinkWrite(s.out, chunk, 0, tailEnd)
605 }
606 s.bufFileOff += s.carryLen + tailEnd
607 s.carryLen = 0
608 return tailEnd
609}
610
611// Strip attr-snaps, truncate on boundaries. Kept lines write as runs.
612function scanChunkLines(

Callers 1

readTranscriptForLoadFunction · 0.85

Calls 4

hasPrefixFunction · 0.85
parseBoundaryLineFunction · 0.85
sinkWriteFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected