* Read the file into a buffer and delegate to parseBuffer so the * decompression-bomb guard runs before SheetJS inflates the workbook.
(filePath: string)
| 23 | * decompression-bomb guard runs before SheetJS inflates the workbook. |
| 24 | */ |
| 25 | async parseFile(filePath: string): Promise<FileParseResult> { |
| 26 | try { |
| 27 | if (!filePath) { |
| 28 | throw new Error('No file path provided') |
| 29 | } |
| 30 | |
| 31 | if (!existsSync(filePath)) { |
| 32 | throw new Error(`File not found: ${filePath}`) |
| 33 | } |
| 34 | |
| 35 | logger.info(`Parsing XLSX file: ${filePath}`) |
| 36 | |
| 37 | const buffer = await readFile(filePath) |
| 38 | return this.parseBuffer(buffer) |
| 39 | } catch (error) { |
| 40 | logger.error('XLSX file parsing error:', error) |
| 41 | throw new Error(`Failed to parse XLSX file: ${(error as Error).message}`) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | async parseBuffer(buffer: Buffer): Promise<FileParseResult> { |
| 46 | try { |
nothing calls this directly
no test coverage detected