(file: string, encoding: BufferEncoding = 'utf-8')
| 39 | * open itself. Throws what a failed open or read throws. |
| 40 | */ |
| 41 | export function readSourceText(file: string, encoding: BufferEncoding = 'utf-8'): string | null { |
| 42 | const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NONBLOCK ?? 0)); |
| 43 | try { |
| 44 | const stats = fs.fstatSync(fd); |
| 45 | if (!stats.isFile() || stats.size > MAX_SOURCE_FILE_SIZE_BYTES) return null; |
| 46 | return fs.readFileSync(fd, encoding); |
| 47 | } finally { |
| 48 | fs.closeSync(fd); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** A source file's stats, and its bytes when they are within the limit (null = oversize). */ |
| 53 | export interface BoundedSource { |
no test coverage detected