MCPcopy Index your code
hub / github.com/codeaashu/claude-code / readFileInRangeStreaming

Function readFileInRangeStreaming

src/utils/readFileInRange.ts:344–383  ·  view source on GitHub ↗
(
  filePath: string,
  offset: number,
  maxLines: number | undefined,
  maxBytes: number | undefined,
  truncateOnByteLimit: boolean,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

342}
343
344function readFileInRangeStreaming(
345 filePath: string,
346 offset: number,
347 maxLines: number | undefined,
348 maxBytes: number | undefined,
349 truncateOnByteLimit: boolean,
350 signal?: AbortSignal,
351): Promise<ReadFileRangeResult> {
352 return new Promise((resolve, reject) => {
353 const state: StreamState = {
354 stream: createReadStream(filePath, {
355 encoding: 'utf8',
356 highWaterMark: 512 * 1024,
357 ...(signal ? { signal } : undefined),
358 }),
359 offset,
360 endLine: maxLines !== undefined ? offset + maxLines : Infinity,
361 maxBytes,
362 truncateOnByteLimit,
363 resolve,
364 totalBytesRead: 0,
365 selectedBytes: 0,
366 truncatedByBytes: false,
367 currentLineIndex: 0,
368 selectedLines: [],
369 partial: '',
370 isFirstChunk: true,
371 resolveMtime: () => {},
372 mtimeReady: null as unknown as Promise<number>,
373 }
374 state.mtimeReady = new Promise<number>(r => {
375 state.resolveMtime = r
376 })
377
378 state.stream.once('open', streamOnOpen.bind(state))
379 state.stream.on('data', streamOnData.bind(state))
380 state.stream.once('end', streamOnEnd.bind(state))
381 state.stream.once('error', reject)
382 })
383}
384

Callers 1

readFileInRangeFunction · 0.85

Calls 1

onMethod · 0.80

Tested by

no test coverage detected