| 60 | }; |
| 61 | |
| 62 | const storeFileInOPFS = async (blob) => { |
| 63 | try { |
| 64 | performance.mark('start-opfs-cache'); |
| 65 | const root = await navigator.storage.getDirectory(); |
| 66 | const handle = await root.getFileHandle('model.bin', { create: true }); |
| 67 | const writable = await handle.createWritable(); |
| 68 | await blob.stream().pipeTo(writable); |
| 69 | performance.mark('end-opfs-cache'); |
| 70 | const mark = performance.measure( |
| 71 | 'opfs-cache', |
| 72 | 'start-opfs-cache', |
| 73 | 'end-opfs-cache' |
| 74 | ); |
| 75 | console.log( |
| 76 | 'Model file cached in OPFS.', |
| 77 | mark.name, |
| 78 | mark.duration.toFixed(2) |
| 79 | ); |
| 80 | } catch (err) { |
| 81 | console.error(err.name, err.message); |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | const storeFileInSWCache = async (blob) => { |
| 86 | try { |