chore(vendor): import pi 1.3.0

Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: 71023aec1546d6d677a65669c5665c0927ce0dd0
This commit is contained in:
alexion committed 2026-10-15 17:58:48 -04:00
1 parent 719370c8f7
commit 6081e3e325
1743 files changed
+205459 -131704

No files matched your search

@@ -0,0 +1,17 @@
// Its own file, so Photon is not yet initialized: vitest gives each file fresh modules, and Photon loads only once.
import { readFile } from "node:fs/promises";
import { createRequire } from "node:module";
import { createPhotonImages } from "@earendil-works/pi-durable/images";
import { DEFAULT_IMAGE_LIMITS } from "@earendil-works/pi-durable/tools";
import { expect, it } from "vitest";
it("createPhotonImages takes a compiled WebAssembly module, as Cloudflare Workers pass it", async () => {
const path = createRequire(import.meta.url).resolve("@silvia-odwyer/photon/photon_rs_bg.wasm");
const { WebAssembly } = globalThis as unknown as { WebAssembly: { compile(bytes: Uint8Array): Promise<object> } };
const module = (await WebAssembly.compile(await readFile(path))) as Parameters<typeof createPhotonImages>[0];
const images = createPhotonImages(module);
// A 1x1 GIF; returned as it is only once it decodes, which fails without an initialized Photon.
const data = "R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
const prepared = await images.prepare(Buffer.from(data, "base64"), "image/gif", DEFAULT_IMAGE_LIMITS);
expect(prepared).toEqual({ data, mimeType: "image/gif" });
});