* Handle a CSV buffer directly in memory
( fileBuffer: Buffer, filename: string, fileType?: string, originalPath?: string, maxParsedOutputBytes?: number )
| 969 | * Handle a CSV buffer directly in memory |
| 970 | */ |
| 971 | async function handleCsvBuffer( |
| 972 | fileBuffer: Buffer, |
| 973 | filename: string, |
| 974 | fileType?: string, |
| 975 | originalPath?: string, |
| 976 | maxParsedOutputBytes?: number |
| 977 | ): Promise<ParseResult> { |
| 978 | try { |
| 979 | logger.info(`Parsing CSV in memory: ${filename}`) |
| 980 | |
| 981 | const { parseBuffer } = await import('@/lib/file-parsers') |
| 982 | const result = await parseBuffer(fileBuffer, 'csv') |
| 983 | |
| 984 | return { |
| 985 | success: true, |
| 986 | content: assertParsedContentWithinLimit(result.content, maxParsedOutputBytes), |
| 987 | filePath: originalPath || filename, |
| 988 | metadata: { |
| 989 | fileType: fileType || 'text/csv', |
| 990 | size: fileBuffer.length, |
| 991 | hash: createHash('md5').update(fileBuffer).digest('hex'), |
| 992 | processingTime: 0, |
| 993 | }, |
| 994 | } |
| 995 | } catch (error) { |
| 996 | if (isPayloadSizeLimitError(error)) throw error |
| 997 | |
| 998 | logger.error('Failed to parse CSV in memory:', error) |
| 999 | return { |
| 1000 | success: false, |
| 1001 | error: `Failed to parse CSV: ${(error as Error).message}`, |
| 1002 | filePath: originalPath || filename, |
| 1003 | metadata: { |
| 1004 | fileType: 'text/csv', |
| 1005 | size: 0, |
| 1006 | hash: '', |
| 1007 | processingTime: 0, |
| 1008 | }, |
| 1009 | } |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | /** |
| 1014 | * Handle a generic text file buffer in memory |
no test coverage detected