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

Function readCapped

src/utils/readEditContext.ts:123–145  ·  view source on GitHub ↗
(handle: FileHandle)

Source from the content-addressed store, hash-verified

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

Callers 2

loadRejectionDiffFunction · 0.85
loadDiffDataFunction · 0.85

Calls 2

normalizeCRLFFunction · 0.85
readMethod · 0.65

Tested by

no test coverage detected