MCPcopy Create free account
hub / github.com/B3Pay/B3Wallet / loadImageFile

Function loadImageFile

scripts/utils.ts:46–68  ·  view source on GitHub ↗
(
  imagePath: string,
  asBase64: T = false as T
)

Source from the content-addressed store, hash-verified

44}
45
46export 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
70export const loadWasmFile = async (name: string, withCandid?: boolean) => {
71 const buffer = await readFile(

Callers 1

createAppFunction · 0.90

Calls 1

fromMethod · 0.45

Tested by

no test coverage detected