import{F as e}from"./FacadeVFS-d1ZDvud7.js";import{j as t,S as a,k as s,n as i,p as c,D as n,F as r,r as o,G as l,H as h,I as d}from"./worker.js";const m=4096,p=o|l|h|d;class u extends e{log=null;#e;#t;#a=new Map;#s=new Map;#i=new Set;#c=new Map;static async create(e,t){const a=new u(e,t);return await a.isReady(),a}constructor(e,t){super(e,t),this.#e=e}jOpen(e,i,c,n){try{const s=e?this.#n(e):Math.random().toString(36);let r=this.#s.get(s);if(!r&&c&t){if(!(this.getSize(){const a=await t.createSyncAccessHandle();this.#a.set(a,e);const s=this.#d(a);s?this.#s.set(s,a):this.#i.add(a)}))}#l(){for(const e of this.#a.keys())e.close();this.#a.clear(),this.#s.clear(),this.#i.clear()}#d(e){const t=new Uint8Array(516);e.read(t,{at:0});const a=new DataView(t.buffer,t.byteOffset).getUint32(512);if(t[0]&&(a&i||0===(a&p)))return console.warn(`Remove file with unexpected flags ${a.toString(16)}`),this.#r(e,"",0),"";const s=new Uint32Array(2);e.read(s,{at:516});const c=this.#m(t);if(s.every((e,t)=>e===c[t])){const a=t.findIndex(e=>0===e);return 0===a&&e.truncate(m),(new TextDecoder).decode(t.subarray(0,a))}return console.warn("Disassociating file with bad digest."),this.#r(e,"",0),""}#r(e,t,a){const s=new Uint8Array(516);if((new TextEncoder).encodeInto(t,s).written>=512)throw new Error("path too long");new DataView(s.buffer,s.byteOffset).setUint32(512,a);const i=this.#m(s);e.write(s,{at:0}),e.write(i,{at:516}),e.flush(),t?(this.#s.set(t,e),this.#i.delete(e)):(e.truncate(m),this.#i.add(e))}#m(e){if(!e[0])return new Uint32Array([4274806656,2899230775]);let t=3735928559,a=1103547991;for(const s of e)t=Math.imul(t^s,2654435761),a=Math.imul(a^s,1597334677);return t=Math.imul(t^t>>>16,2246822507)^Math.imul(a^a>>>13,3266489909),a=Math.imul(a^a>>>16,2246822507)^Math.imul(t^t>>>13,3266489909),new Uint32Array([t>>>0,a>>>0])}#n(e){return("string"==typeof e?new URL(e,"file://localhost/"):e).pathname}#o(e){const t=this.#s.get(e);t&&(this.#s.delete(e),this.#r(t,"",0))}}export{u as AccessHandlePoolVFS}; //# sourceMappingURL=AccessHandlePoolVFS-BPUHfZME.js.map