( taskId: string, fromOffset: number, maxBytes: number = DEFAULT_MAX_READ_BYTES, )
| 304 | * Reads only from the byte offset, up to maxBytes — never loads the full file. |
| 305 | */ |
| 306 | export async function getTaskOutputDelta( |
| 307 | taskId: string, |
| 308 | fromOffset: number, |
| 309 | maxBytes: number = DEFAULT_MAX_READ_BYTES, |
| 310 | ): Promise<{ content: string; newOffset: number }> { |
| 311 | try { |
| 312 | const result = await readFileRange( |
| 313 | getTaskOutputPath(taskId), |
| 314 | fromOffset, |
| 315 | maxBytes, |
| 316 | ) |
| 317 | if (!result) { |
| 318 | return { content: '', newOffset: fromOffset } |
| 319 | } |
| 320 | return { |
| 321 | content: result.content, |
| 322 | newOffset: fromOffset + result.bytesRead, |
| 323 | } |
| 324 | } catch (e) { |
| 325 | const code = getErrnoCode(e) |
| 326 | if (code === 'ENOENT') { |
| 327 | return { content: '', newOffset: fromOffset } |
| 328 | } |
| 329 | logError(e) |
| 330 | return { content: '', newOffset: fromOffset } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Get output for a task, reading the tail of the file. |
no test coverage detected