* Handle a generic binary buffer
( fileBuffer: Buffer, filename: string, extension: string, fileType?: string, maxParsedOutputBytes?: number )
| 1084 | * Handle a generic binary buffer |
| 1085 | */ |
| 1086 | function handleGenericBuffer( |
| 1087 | fileBuffer: Buffer, |
| 1088 | filename: string, |
| 1089 | extension: string, |
| 1090 | fileType?: string, |
| 1091 | maxParsedOutputBytes?: number |
| 1092 | ): ParseResult { |
| 1093 | const normalizedExtension = extension.toLowerCase() |
| 1094 | const content = |
| 1095 | !BINARY_EXTENSIONS.has(normalizedExtension) && isLikelyTextBuffer(fileBuffer) |
| 1096 | ? assertParsedContentWithinLimit(fileBuffer.toString('utf-8'), maxParsedOutputBytes) |
| 1097 | : `[Binary ${normalizedExtension.toUpperCase()} file - ${fileBuffer.length} bytes]` |
| 1098 | |
| 1099 | return { |
| 1100 | success: true, |
| 1101 | content, |
| 1102 | filePath: filename, |
| 1103 | metadata: { |
| 1104 | fileType: fileType || getMimeTypeFromExtension(extension), |
| 1105 | size: fileBuffer.length, |
| 1106 | hash: createHash('md5').update(fileBuffer).digest('hex'), |
| 1107 | processingTime: 0, |
| 1108 | }, |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | /** |
| 1113 | * Parse a PDF buffer |
no test coverage detected