Component evidence

File Size Limits and Bounded Reader (src/file-limits.ts)

codegraph · src/file-limits.ts · typescript · MIT
fileslang:typescripttag:iotag:performance

A TypeScript utility providing file size validation, bounded reading, and memory-safe handling for large source files. Reuse this to prevent memory spikes when parsing source code repositories.

Source preview first 800 characters · full source over MCP
// Source: https://github.com/colbymchenry/codegraph | License: MIT | Copyright 2026 Colby Mchenry
// Provided via justclaw.it.com; keep this notice with the code.
import * as fs from 'fs';
import * as fsp from 'fs/promises';

/**
 * Largest source file CodeGraph will parse or read during resolution. Generated
 * bundles, minified sources, and dependency archives above this limit provide no
 * useful symbols; 1 MB covers essentially all hand-written source.
 */
export const MAX_SOURCE_FILE_SIZE_BYTES = 1024 * 1024;

/**
 * What stands in for the content of a file over MAX_SOURCE_FILE_SIZE_BYTES. Such a file is
 * never parsed, so its bytes are never needed — reading them only to hash and
 * discard cost multi-GB RSS spikes on committed video/blob fixtures and could
 * fail outright with `I

... (truncated -- full source via MCP)