MCPcopy Index your code
hub / github.com/coder/mux / readFileViaExec

Method readFileViaExec

src/node/runtime/DevcontainerRuntime.ts:290–331  ·  view source on GitHub ↗
(filePath: string, abortSignal?: AbortSignal)

Source from the content-addressed store, hash-verified

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,

Callers 1

readFileMethod · 0.95

Calls 8

execMethod · 0.95
quoteForContainerMethod · 0.95
getContainerBasePathMethod · 0.95
streamToStringFunction · 0.90
getErrorMessageFunction · 0.90
enqueueMethod · 0.80
closeMethod · 0.65
readMethod · 0.45

Tested by

no test coverage detected