Skip to content

Commit

Permalink
fix: deno.core base64 removal patch
Browse files Browse the repository at this point in the history
  • Loading branch information
load1n9 committed Jan 22, 2024
1 parent 210f946 commit 5152c24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
12 changes: 5 additions & 7 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { encodeBase64 } from "https://deno.land/std@0.212.0/encoding/base64.ts";

const $ = (cmd: string, ...args: string[]) => {
console.log(`%c$ ${cmd} ${args.join(" ")}`, "color: #888");
return new Deno.Command(cmd, {
Expand Down Expand Up @@ -62,15 +64,11 @@ const OUT_FILE = `./glfw3_${Deno.build.os}${
Deno.build.arch === "aarch64" ? "_aarch64" : ""
}.js`;

const encode = (Deno as any)[(Deno as any).internal]
.core
.ops.op_base64_encode;

Deno.writeTextFileSync(
OUT_FILE,
`const BASE64 = "${
encode(Deno.readFileSync(BIN_FILE))
}";\nconst DECODED = Deno.build.os === "${Deno.build.os}" && Deno.build.arch === "${Deno.build.arch}" ? Deno[Deno.internal].core.ops.op_base64_decode(BASE64) : new Uint8Array();\nexport default DECODED;\n`,
`import { decodeBase64 } from "https://deno.land/std@0.212.0/encoding/base64.ts";\nconst BASE64 = "${
encodeBase64(Deno.readFileSync(BIN_FILE))
}";\nconst DECODED = Deno.build.os === "${Deno.build.os}" && Deno.build.arch === "${Deno.build.arch}" ? decodeBase64(BASE64) : new Uint8Array();\nexport default DECODED;\n`,
);

console.log(`%cWrote ${OUT_FILE}`, "color: #888");
9 changes: 6 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ import bin from "./glfw3_linux.js";
const start = performance.now();
const tmp = Deno.makeTempFileSync();
Deno.writeFileSync(tmp, bin);
const ffi = Deno.dlopen(tmp, {
glfwInit: { parameters: [], result: "i32" },
} as const).symbols;
const ffi = Deno.dlopen(
tmp,
{
glfwInit: { parameters: [], result: "i32" },
} as const,
).symbols;
Deno.removeSync(tmp);
const end = performance.now();
console.log(`Loaded in ${end - start}ms`);
Expand Down

0 comments on commit 5152c24

Please sign in to comment.