MCPcopy
hub / github.com/vercel-labs/just-bash / readFiles

Function readFiles

packages/just-bash/src/utils/file-reader.ts:58–128  ·  view source on GitHub ↗
(
  ctx: CommandContext,
  files: string[],
  options: ReadFilesOptions,
)

Source from the content-addressed store, hash-verified

56 * }
57 */
58export async function readFiles(
59 ctx: CommandContext,
60 files: string[],
61 options: ReadFilesOptions,
62): Promise<ReadFilesResult> {
63 const {
64 cmdName,
65 allowStdinMarker = true,
66 stopOnError = false,
67 batchSize = DEFAULT_BATCH_SIZE,
68 } = options;
69
70 // No files - read from stdin
71 if (files.length === 0) {
72 return {
73 files: [{ filename: "", content: ctx.stdin }],
74 stderr: "",
75 exitCode: 0,
76 };
77 }
78
79 const result: FileContent[] = [];
80 let stderr = "";
81 let exitCode = 0;
82
83 // Process files in parallel batches for better performance
84 for (let i = 0; i < files.length; i += batchSize) {
85 const batch = files.slice(i, i + batchSize);
86 const batchResults = await Promise.all(
87 batch.map(async (file) => {
88 if (allowStdinMarker && file === "-") {
89 return {
90 filename: "-",
91 content: ctx.stdin,
92 error: null as string | null,
93 };
94 }
95 try {
96 const filePath = ctx.fs.resolvePath(ctx.cwd, file);
97 // Use binary encoding to preserve all bytes (including non-UTF-8).
98 // This is important for piping binary data through commands like cat.
99 // Text-processing commands must explicitly call `decodeBytesToUtf8`
100 // on the content before regex / parsing.
101 const content = await readBytesFrom(ctx.fs, filePath);
102 return { filename: file, content, error: null as string | null };
103 } catch {
104 return {
105 filename: file,
106 content: EMPTY_BYTES,
107 error: `${cmdName}: ${file}: No such file or directory\n`,
108 };
109 }
110 }),
111 );
112
113 // Process results in order
114 for (const r of batchResults) {
115 if (r.error) {

Callers 5

readAndConcatFunction · 0.85
executeFunction · 0.85
executeFunction · 0.85
executeFunction · 0.85
cmdCatFunction · 0.85

Calls 2

readBytesFromFunction · 0.85
resolvePathMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…