MCPcopy Create free account
hub / github.com/altic-dev/Pilot / readFile

Function readFile

src/lib/docker.ts:178–220  ·  view source on GitHub ↗
(sessionId: string, filePath: string)

Source from the content-addressed store, hash-verified

176 * Read a file from the container
177 */
178export async function readFile(sessionId: string, filePath: string): Promise<string> {
179 const container = containerCache.get(sessionId);
180 if (!container) {
181 throw new Error(`No container found for session: ${sessionId}`);
182 }
183
184 try {
185 const stream = await container.getArchive({ path: filePath });
186 const extract = tar.extract();
187
188 return new Promise<string>((resolve, reject) => {
189 let content = '';
190
191 extract.on('entry', (header, entryStream, next) => {
192 const chunks: Buffer[] = [];
193
194 entryStream.on('data', (chunk: Buffer) => {
195 chunks.push(chunk);
196 });
197
198 entryStream.on('end', () => {
199 content = Buffer.concat(chunks).toString('utf-8');
200 next();
201 });
202
203 entryStream.resume();
204 });
205
206 extract.on('finish', () => {
207 resolve(content);
208 });
209
210 extract.on('error', (err) => {
211 reject(err);
212 });
213
214 stream.pipe(extract);
215 });
216 } catch (error) {
217 logger.error('Failed to read file from container', { sessionId, filePath, error });
218 throw new Error(`Failed to read file: ${error}`);
219 }
220}
221
222/**
223 * List directory contents in the container

Callers 6

injectNextJsMethod · 0.90
injectHtmlTemplateMethod · 0.90
cleanupInjectionMethod · 0.90
detectBuildConfigFunction · 0.90
GETFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected