MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / readCapped

Function readCapped

source code/utils/readEditContext.ts:125–147  ·  view source on GitHub ↗
(handle: FileHandle)

Source from the content-addressed store, hash-verified

123 * chunks + concat. Reads directly into the right offset; no intermediate copies.
124 */
125export async function readCapped(handle: FileHandle): Promise<string | null> {
126 let buf = Buffer.allocUnsafe(CHUNK_SIZE)
127 let total = 0
128 for (;;) {
129 if (total === buf.length) {
130 const grown = Buffer.allocUnsafe(
131 Math.min(buf.length * 2, MAX_SCAN_BYTES + CHUNK_SIZE),
132 )
133 buf.copy(grown, 0, 0, total)
134 buf = grown
135 }
136 const { bytesRead } = await handle.read(
137 buf,
138 total,
139 buf.length - total,
140 total,
141 )
142 if (bytesRead === 0) break
143 total += bytesRead
144 if (total > MAX_SCAN_BYTES) return null
145 }
146 return normalizeCRLF(buf, total)
147}
148
149/** buf.indexOf bounded to [0, end) without allocating a view. */
150function indexOfWithin(buf: Buffer, needle: Buffer, end: number): number {

Callers 2

loadRejectionDiffFunction · 0.85
loadDiffDataFunction · 0.85

Calls 2

normalizeCRLFFunction · 0.85
readMethod · 0.45

Tested by

no test coverage detected