( absPath: string, start: number, end: number, )
| 595 | } |
| 596 | |
| 597 | async function readFileRange( |
| 598 | absPath: string, |
| 599 | start: number, |
| 600 | end: number, |
| 601 | ): Promise<Buffer> { |
| 602 | if (end <= start) return Buffer.alloc(0); |
| 603 | const fh = await fs.open(absPath, 'r'); |
| 604 | try { |
| 605 | const length = end - start; |
| 606 | const buf = Buffer.allocUnsafe(length); |
| 607 | const { bytesRead } = await fh.read(buf, 0, length, start); |
| 608 | return bytesRead === length ? buf : buf.subarray(0, bytesRead); |
| 609 | } finally { |
| 610 | await fh.close(); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | const EXT_TO_MIME: Readonly<Record<string, string>> = { |
| 615 | '.ts': 'text/typescript', |
no test coverage detected