MCPcopy
hub / github.com/coder/mux / readBoundedTextFile

Method readBoundedTextFile

src/node/services/memoryService.ts:883–895  ·  view source on GitHub ↗

* Bounded full-file read for every whole-file path (view, edits, UI read, * save compare). Memory files can be edited outside MemoryService write caps, * so an unbounded read of a degenerate file could hang the main process or * blow up the stream context. Reads at most cap+1 bytes and reje

(
    store: MemoryStore,
    relPath: string,
    virtualPath: string
  )

Source from the content-addressed store, hash-verified

881 * and the bytes must be read first).
882 */
883 private async readBoundedTextFile(
884 store: MemoryStore,
885 relPath: string,
886 virtualPath: string
887 ): Promise<string> {
888 const content = await store.readFilePrefix(relPath, MEMORY_MAX_FILE_BYTES + 1);
889 if (Buffer.byteLength(content, "utf-8") > MEMORY_MAX_FILE_BYTES) {
890 throw new MemoryCommandError(
891 `${virtualPath} exceeds the ${MEMORY_MAX_FILE_BYTES}-byte memory file cap (likely edited outside Mux, bypassing write caps); shrink or delete it`
892 );
893 }
894 return content;
895 }
896
897 private async readTextFileForEdit(
898 store: MemoryStore,

Callers 3

viewMethod · 0.95
readTextFileForEditMethod · 0.95
saveFileMethod · 0.95

Calls 1

readFilePrefixMethod · 0.65

Tested by

no test coverage detected