MCPcopy
hub / github.com/claude-code-best/claude-code / readTranscriptForLoad

Function readTranscriptForLoad

src/utils/sessionStoragePortable.ts:715–791  ·  view source on GitHub ↗
(
  filePath: string,
  fileSize: number,
)

Source from the content-addressed store, hash-verified

713}
714
715export async function readTranscriptForLoad(
716 filePath: string,
717 fileSize: number,
718): Promise<{
719 boundaryStartOffset: number
720 postBoundaryBuf: Buffer
721 hasPreservedSegment: boolean
722}> {
723 const boundaryMarker = compactBoundaryMarker()
724 const CHUNK_SIZE = TRANSCRIPT_READ_CHUNK_SIZE
725
726 const s: LoadState = {
727 out: {
728 // Gated callers enter with fileSize > 5MB, so min(fileSize, 8MB) lands
729 // in [5, 8]MB; large boundaryless sessions (24-31MB output) take 2
730 // grows. Ungated callers (attribution.ts) pass small files too — the
731 // min just right-sizes the initial buf, no grows.
732 buf: Buffer.allocUnsafe(Math.min(fileSize, 8 * 1024 * 1024)),
733 len: 0,
734 // +1: finalizeOutput may insert one LF between a non-LF-terminated
735 // carry and the reordered last attr-snap (crash-truncated file).
736 cap: fileSize + 1,
737 },
738 boundaryStartOffset: 0,
739 hasPreservedSegment: false,
740 lastSnapSrc: null,
741 lastSnapLen: 0,
742 lastSnapBuf: undefined,
743 bufFileOff: 0,
744 carryLen: 0,
745 carryBuf: undefined,
746 straddleSnapCarryLen: 0,
747 straddleSnapTailEnd: 0,
748 }
749
750 const chunk = Buffer.allocUnsafe(CHUNK_SIZE)
751 const fd = await fsOpen(filePath, 'r')
752 try {
753 let filePos = 0
754 while (filePos < fileSize) {
755 const { bytesRead } = await fd.read(
756 chunk,
757 0,
758 Math.min(CHUNK_SIZE, fileSize - filePos),
759 filePos,
760 )
761 if (bytesRead === 0) break
762 filePos += bytesRead
763
764 const chunkOff = processStraddle(s, chunk, bytesRead)
765
766 let buf: Buffer
767 if (s.carryLen > 0) {
768 const bufLen = s.carryLen + (bytesRead - chunkOff)
769 buf = Buffer.allocUnsafe(bufLen)
770 s.carryBuf!.copy(buf, 0, 0, s.carryLen)
771 chunk.copy(buf, s.carryLen, chunkOff, bytesRead)
772 } else {

Callers 2

loadTranscriptFileFunction · 0.85
getTranscriptStatsFunction · 0.85

Calls 8

compactBoundaryMarkerFunction · 0.85
processStraddleFunction · 0.85
scanChunkLinesFunction · 0.85
captureSnapFunction · 0.85
captureCarryFunction · 0.85
finalizeOutputFunction · 0.85
closeMethod · 0.65
readMethod · 0.45

Tested by

no test coverage detected