(file: string, encoding: BufferEncoding = 'utf-8')
| 46 | * open itself. Throws what a failed open or read throws. |
| 47 | */ |
| 48 | export function readSourceText(file: string, encoding: BufferEncoding = 'utf-8'): string | null { |
| 49 | const fd = fs.openSync(file, fs.constants.O_RDONLY | (fs.constants.O_NONBLOCK ?? 0)); |
| 50 | try { |
| 51 | const stats = fs.fstatSync(fd); |
| 52 | if (!stats.isFile() || stats.size > MAX_SOURCE_FILE_SIZE_BYTES) return null; |
| 53 | return fs.readFileSync(fd, encoding); |
| 54 | } finally { |
| 55 | fs.closeSync(fd); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * The longest run of name characters a pattern is given as written. No name, |
no test coverage detected