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

Function readJSONLFile

source code/utils/json.ts:203–228  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected