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

Function readJSONLFile

src/utils/json.ts:201–226  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

199 * is ~2M tokens, which is well under 100 MB of JSONL.
200 */
201export async function readJSONLFile<T>(filePath: string): Promise<T[]> {
202 const { size } = await stat(filePath)
203 if (size <= MAX_JSONL_READ_BYTES) {
204 return parseJSONL<T>(await readFile(filePath))
205 }
206 await using fd = await open(filePath, 'r')
207 const buf = Buffer.allocUnsafe(MAX_JSONL_READ_BYTES)
208 let totalRead = 0
209 const fileOffset = size - MAX_JSONL_READ_BYTES
210 while (totalRead < MAX_JSONL_READ_BYTES) {
211 const { bytesRead } = await fd.read(
212 buf,
213 totalRead,
214 MAX_JSONL_READ_BYTES - totalRead,
215 fileOffset + totalRead,
216 )
217 if (bytesRead === 0) break
218 totalRead += bytesRead
219 }
220 // Skip the first partial line
221 const newlineIndex = buf.indexOf(0x0a)
222 if (newlineIndex !== -1 && newlineIndex < totalRead - 1) {
223 return parseJSONL<T>(buf.subarray(newlineIndex + 1, totalRead))
224 }
225 return parseJSONL<T>(buf.subarray(0, totalRead))
226}
227
228export function addItemToJSONCArray(content: string, newItem: unknown): string {
229 try {

Callers

nothing calls this directly

Calls 5

statFunction · 0.85
parseJSONLFunction · 0.85
readFileFunction · 0.85
openFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected