(filePath: string, onLine: (line: CodexLine) => void)
| 416 | } |
| 417 | |
| 418 | function readCodexJsonlStreaming(filePath: string, onLine: (line: CodexLine) => void): void { |
| 419 | const fd = fs.openSync(filePath, 'r'); |
| 420 | const decoder = new StringDecoder('utf8'); |
| 421 | const buffer = Buffer.allocUnsafe(1024 * 1024); |
| 422 | let remainder = ''; |
| 423 | |
| 424 | try { |
| 425 | while (true) { |
| 426 | const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, null); |
| 427 | if (bytesRead === 0) break; |
| 428 | const text = remainder + decoder.write(buffer.subarray(0, bytesRead)); |
| 429 | let start = 0; |
| 430 | let nextNewline = text.indexOf('\n', start); |
| 431 | while (nextNewline !== -1) { |
| 432 | const rawLine = text.slice(start, nextNewline); |
| 433 | if (rawLine.trim()) { |
| 434 | const parsed = parseCodexLine(rawLine); |
| 435 | if (parsed) onLine(parsed); |
| 436 | } |
| 437 | start = nextNewline + 1; |
| 438 | nextNewline = text.indexOf('\n', start); |
| 439 | } |
| 440 | remainder = text.slice(start); |
| 441 | } |
| 442 | |
| 443 | remainder += decoder.end(); |
| 444 | if (remainder.trim()) { |
| 445 | const parsed = parseCodexLine(remainder); |
| 446 | if (parsed) onLine(parsed); |
| 447 | } |
| 448 | } finally { |
| 449 | fs.closeSync(fd); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | export function findCodexDirs(): string[] { |
| 454 | const home = process.env.HOME || process.env.USERPROFILE || ''; |
no test coverage detected