| 44 | } |
| 45 | |
| 46 | export const loadImageFile = <T extends boolean>( |
| 47 | imagePath: string, |
| 48 | asBase64: T = false as T |
| 49 | ): T extends true ? string : Buffer => { |
| 50 | const fullPath = path.join(process.cwd(), imagePath) |
| 51 | const image = readFileSync(fullPath) |
| 52 | |
| 53 | // Extract the file extension and determine the MIME type |
| 54 | const ext = path.extname(fullPath).toLowerCase() |
| 55 | |
| 56 | const imageBuffer = Buffer.from(image) |
| 57 | |
| 58 | if (asBase64 === false) { |
| 59 | return imageBuffer as any |
| 60 | } |
| 61 | |
| 62 | let mimeType = "image/jpeg" // Default MIME type |
| 63 | if (ext === ".png") mimeType = "image/png" |
| 64 | else if (ext === ".svg") mimeType = "image/svg+xml" |
| 65 | |
| 66 | // Return the formatted Base64 string with the prefix |
| 67 | return `data:${mimeType};base64,${imageBuffer.toString("base64")}` as any |
| 68 | } |
| 69 | |
| 70 | export const loadWasmFile = async (name: string, withCandid?: boolean) => { |
| 71 | const buffer = await readFile( |