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

Function processStraddle

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

Source from the content-addressed store, hash-verified

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