(filePath: string, abortSignal?: AbortSignal)
| 288 | } |
| 289 | |
| 290 | private readFileViaExec(filePath: string, abortSignal?: AbortSignal): ReadableStream<Uint8Array> { |
| 291 | return new ReadableStream<Uint8Array>({ |
| 292 | start: async (controller) => { |
| 293 | try { |
| 294 | const stream = await this.exec(`cat ${this.quoteForContainer(filePath)}`, { |
| 295 | cwd: this.getContainerBasePath(), |
| 296 | timeout: 300, |
| 297 | abortSignal, |
| 298 | }); |
| 299 | |
| 300 | const reader = stream.stdout.getReader(); |
| 301 | const exitCodePromise = stream.exitCode; |
| 302 | |
| 303 | while (true) { |
| 304 | const { done, value } = await reader.read(); |
| 305 | if (done) break; |
| 306 | controller.enqueue(value); |
| 307 | } |
| 308 | |
| 309 | const code = await exitCodePromise; |
| 310 | if (code !== 0) { |
| 311 | const stderr = await streamToString(stream.stderr); |
| 312 | throw new RuntimeError(`Failed to read file ${filePath}: ${stderr}`, "file_io"); |
| 313 | } |
| 314 | |
| 315 | controller.close(); |
| 316 | } catch (err) { |
| 317 | if (err instanceof RuntimeError) { |
| 318 | controller.error(err); |
| 319 | } else { |
| 320 | controller.error( |
| 321 | new RuntimeError( |
| 322 | `Failed to read file ${filePath}: ${getErrorMessage(err)}`, |
| 323 | "file_io", |
| 324 | err instanceof Error ? err : undefined |
| 325 | ) |
| 326 | ); |
| 327 | } |
| 328 | } |
| 329 | }, |
| 330 | }); |
| 331 | } |
| 332 | |
| 333 | private writeFileViaExec( |
| 334 | filePath: string, |
no test coverage detected