MCPcopy Index your code
hub / github.com/simstudioai/sim / handleGenericBuffer

Function handleGenericBuffer

apps/sim/app/api/files/parse/route.ts:1086–1110  ·  view source on GitHub ↗

* Handle a generic binary buffer

(
  fileBuffer: Buffer,
  filename: string,
  extension: string,
  fileType?: string,
  maxParsedOutputBytes?: number
)

Source from the content-addressed store, hash-verified

1084 * Handle a generic binary buffer
1085 */
1086function 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

Callers 2

handleExternalUrlFunction · 0.85
handleCloudFileFunction · 0.85

Calls 4

getMimeTypeFromExtensionFunction · 0.90
isLikelyTextBufferFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected