Truncate a buffer from the front, keeping the tail.
(buf: string, chunk: string)
| 44 | |
| 45 | /** Truncate a buffer from the front, keeping the tail. */ |
| 46 | function appendCapped(buf: string, chunk: string): string { |
| 47 | const combined = buf + chunk; |
| 48 | if (combined.length <= MAX_BUFFER_BYTES) return combined; |
| 49 | // Drop the oldest 25% to avoid copying on every single line of output. |
| 50 | const keepFrom = Math.floor(MAX_BUFFER_BYTES * 0.75); |
| 51 | return '…[earlier output truncated]…\n' + combined.slice(combined.length - keepFrom); |
| 52 | } |
| 53 | |
| 54 | export interface StartOptions { |
| 55 | name: string; |