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

Function readFileInChunks

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

Source from the content-addressed store, hash-verified

758 * Reads a file in chunks to avoid loading entire file into memory.
759 */
760export async function* readFileInChunks(
761 filePath: string,
762 chunkSize: number = 64 * 1024
763): AsyncGenerator<string, void, undefined> {
764 const fs = await import('fs');
765
766 const fd = fs.openSync(filePath, 'r');
767 const buffer = Buffer.alloc(chunkSize);
768
769 try {
770 let bytesRead: number;
771 while ((bytesRead = fs.readSync(fd, buffer, 0, chunkSize, null)) > 0) {
772 yield buffer.toString('utf-8', 0, bytesRead);
773 }
774 } finally {
775 fs.closeSync(fd);
776 }
777}
778
779/**
780 * Debounce a function

Callers

nothing calls this directly

Calls 1

openSyncMethod · 0.45

Tested by

no test coverage detected