Download src/cache-worker.js from ProCreations/minicpm5-2b-webgpu: direct link, hf CLI and curl.
- Browser
- Download file 777 Bytes
-
https://huggingface.co/spaces/ProCreations/minicpm5-2b-webgpu/resolve/main/src/cache-worker.js
- Command line
-
hf download hf://spaces/ProCreations/minicpm5-2b-webgpu/src/cache-worker.js
-
curl -L -o cache-worker.js https://huggingface.co/spaces/ProCreations/minicpm5-2b-webgpu/resolve/main/src/cache-worker.js
777 Bytes
| let handle; | |
| onmessage=async({data})=>{ | |
| try{ | |
| if(data.action==='open'){ | |
| const root=await navigator.storage.getDirectory();const dir=await root.getDirectoryHandle('cache',{create:true});const file=await dir.getFileHandle(data.key,{create:true}); | |
| handle=await file.createSyncAccessHandle();handle.truncate(0); | |
| }else if(data.action==='write'){ | |
| const bytes=new Uint8Array(data.buffer);let offset=0;while(offset<bytes.length){const wrote=handle.write(bytes.subarray(offset));if(!wrote)throw new Error('The browser cache write made no progress.');offset+=wrote;} | |
| }else if(data.action==='close'){ | |
| handle?.flush();handle?.close();handle=null; | |
| } | |
| postMessage({ok:true}); | |
| }catch(error){try{handle?.close();}catch{}handle=null;postMessage({error:error.message});} | |
| }; | |