/// const canvas = document.createElement("canvas") canvas.style.position = "absolute" canvas.style.top = "0px" canvas.style.left = "0px" canvas.style.width = "100vw" canvas.style.height = "100vh" document.body.append(canvas) const ctx = canvas.getContext("2d")! function draw() { ctx.fillStyle = "black" ctx.fillRect(0, 0, canvas.width, canvas.height) } canvas.addEventListener("resize", () => draw()) draw() class Resource { constructor(public hash: Uint8Array) { } toString() { return Array.from(this.hash) .map(e => e.toString(16).padStart(2, "0")) .join("") } async download_raw() { const res = await fetch(`http://127.0.0.1:28556/${this.toString()}`) if (!res.ok) throw new Error("aaaa"); return await res.bytes() } } function read_res_table(buffer: Uint8Array): { [key: string]: Uint8Array[] } { const view = new DataView(buffer.buffer) let p = 0 const out: { [key: string]: Uint8Array[] } = {} while (p < view.byteLength) { const key_len = view.getInt16(p, true) p += 2 const value_len = view.getInt16(p, true) p += 2 const key = String.fromCharCode(...buffer.slice(p, p + key_len)) p += key_len const value = buffer.slice(p, p + value_len) p += value_len out[key] ??= [] out[key].push(value) } return out } async function init() { const resp = await fetch("http://127.0.0.1:28556/entry") if (!resp.ok) throw new Error("aaaa"); const entry_res = new Resource(await resp.bytes()) const entry = await entry_res.download_raw() console.log(read_res_table(entry)) } init()