(lines: BufferLine[])
| 396 | } |
| 397 | |
| 398 | private appendLines(lines: BufferLine[]): void { |
| 399 | try { |
| 400 | fs.mkdirSync(this.dir, { recursive: true, mode: 0o700 }); |
| 401 | const payload = lines.map((l) => JSON.stringify(l)).join('\n') + '\n'; |
| 402 | // Cap the buffer: drop oldest lines first (telemetry is best-effort — |
| 403 | // bounded disk use beats completeness). |
| 404 | let existing = ''; |
| 405 | try { existing = fs.readFileSync(this.queuePath, 'utf8'); } catch { /* no queue yet */ } |
| 406 | let combined = existing + payload; |
| 407 | if (combined.length > MAX_BUFFER_BYTES) { |
| 408 | combined = combined.slice(combined.length - MAX_BUFFER_BYTES); |
| 409 | combined = combined.slice(combined.indexOf('\n') + 1); // drop the partial first line |
| 410 | } |
| 411 | fs.writeFileSync(this.queuePath, combined); |
| 412 | } catch { |
| 413 | /* fail silent */ |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * Atomically claim the queue for sending (rename). Concurrent processes |
no test coverage detected