blob: 8bfc93714c7232b38f10d18d9c78defacd9afd6a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import { readFileSync } from "fs";
import { resolve } from "path";
export function dataURI(expr) {
const [pathNode, relativeNode] = expr.arguments;
const path = pathNode.toString();
const relative = relativeNode.toString();
try {
const toLoad = resolve(process.cwd(), relative, "../", path);
const data = readFileSync(toLoad);
return `data:${Bun.file(toLoad).type};base64, ${btoa(
String.fromCharCode(...new Uint8Array(data.buffer))
)}`;
} catch (e) {
console.error(e);
return "";
}
}
|