MCPcopy
hub / github.com/colbymchenry/codegraph / readFileInChunks

Function readFileInChunks

src/utils.ts:427–444  ·  view source on GitHub ↗
(
  filePath: string,
  chunkSize: number = 64 * 1024
)

Source from the content-addressed store, hash-verified

425 * Reads a file in chunks to avoid loading entire file into memory.
426 */
427export async function* readFileInChunks(
428 filePath: string,
429 chunkSize: number = 64 * 1024
430): AsyncGenerator<string, void, undefined> {
431 const fs = await import('fs');
432
433 const fd = fs.openSync(filePath, 'r');
434 const buffer = Buffer.alloc(chunkSize);
435
436 try {
437 let bytesRead: number;
438 while ((bytesRead = fs.readSync(fd, buffer, 0, chunkSize, null)) > 0) {
439 yield buffer.toString('utf-8', 0, bytesRead);
440 }
441 } finally {
442 fs.closeSync(fd);
443 }
444}
445
446/**
447 * Debounce a function

Callers

nothing calls this directly

Calls 1

openSyncMethod · 0.80

Tested by

no test coverage detected