MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / readSourceText

Function readSourceText

src/file-limits.ts:41–50  ·  view source on GitHub ↗
(file: string, encoding: BufferEncoding = 'utf-8')

Source from the content-addressed store, hash-verified

39 * open itself. Throws what a failed open or read throws.
40 */
41export function readSourceText(file: string, encoding: BufferEncoding = 'utf-8'): string | null {
42 const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NONBLOCK ?? 0));
43 try {
44 const stats = fs.fstatSync(fd);
45 if (!stats.isFile() || stats.size > MAX_SOURCE_FILE_SIZE_BYTES) return null;
46 return fs.readFileSync(fd, encoding);
47 } finally {
48 fs.closeSync(fd);
49 }
50}
51
52/** A source file's stats, and its bytes when they are within the limit (null = oversize). */
53export interface BoundedSource {

Callers 3

readFileCachedMethod · 0.90
scanFileMethod · 0.90
readTextFunction · 0.90

Calls 1

openSyncMethod · 0.45

Tested by

no test coverage detected