MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / readFilePrefix

Function readFilePrefix

src/util/agent/fsOperations.ts:172–184  ·  view source on GitHub ↗
(filePath: string, maxBytes: number)

Source from the content-addressed store, hash-verified

170}
171
172async function readFilePrefix(filePath: string, maxBytes: number): Promise<string> {
173 const handle = await fs.open(filePath, 'r');
174
175 try {
176 const buffer = Buffer.alloc(maxBytes);
177 const { bytesRead } = await handle.read(buffer, 0, maxBytes, 0);
178 // Decode only the bounded prefix and drop any incomplete trailing code point.
179 const decoder = new StringDecoder('utf8');
180 return decoder.write(buffer.subarray(0, bytesRead));
181 } finally {
182 await handle.close();
183 }
184}

Callers 1

readFileFunction · 0.85

Calls 2

writeMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…