MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / readFileInRange

Function readFileInRange

source code/utils/readFileInRange.ts:75–124  ·  view source on GitHub ↗
(
  filePath: string,
  offset = 0,
  maxLines?: number,
  maxBytes?: number,
  signal?: AbortSignal,
  options?: { truncateOnByteLimit?: boolean },
)

Source from the content-addressed store, hash-verified

73// ---------------------------------------------------------------------------
74
75export async function readFileInRange(
76 filePath: string,
77 offset = 0,
78 maxLines?: number,
79 maxBytes?: number,
80 signal?: AbortSignal,
81 options?: { truncateOnByteLimit?: boolean },
82): Promise<ReadFileRangeResult> {
83 signal?.throwIfAborted()
84 const truncateOnByteLimit = options?.truncateOnByteLimit ?? false
85
86 // stat to decide the code path and guard against OOM.
87 // For regular files under 10 MB: readFile + in-memory split (fast).
88 // Everything else (large files, FIFOs, devices): streaming.
89 const stats = await fsStat(filePath)
90
91 if (stats.isDirectory()) {
92 throw new Error(
93 `EISDIR: illegal operation on a directory, read '${filePath}'`,
94 )
95 }
96
97 if (stats.isFile() && stats.size < FAST_PATH_MAX_SIZE) {
98 if (
99 !truncateOnByteLimit &&
100 maxBytes !== undefined &&
101 stats.size > maxBytes
102 ) {
103 throw new FileTooLargeError(stats.size, maxBytes)
104 }
105
106 const text = await readFile(filePath, { encoding: 'utf8', signal })
107 return readFileInRangeFast(
108 text,
109 stats.mtimeMs,
110 offset,
111 maxLines,
112 truncateOnByteLimit ? maxBytes : undefined,
113 )
114 }
115
116 return readFileInRangeStreaming(
117 filePath,
118 offset,
119 maxLines,
120 maxBytes,
121 truncateOnByteLimit,
122 signal,
123 )
124}
125
126// ---------------------------------------------------------------------------
127// Fast path — readFile + in-memory split

Callers 5

callInnerFunction · 0.85
GlobalSearchDialogFunction · 0.85
QuickOpenDialogFunction · 0.85
readMemoriesForSurfacingFunction · 0.85
scanMemoryFilesFunction · 0.85

Calls 3

readFileFunction · 0.85
readFileInRangeFastFunction · 0.85
readFileInRangeStreamingFunction · 0.85

Tested by

no test coverage detected