MCPcopy Create free account
hub / github.com/GoogleChrome/samples / storeFileInOPFS

Function storeFileInOPFS

mediapipe-llm/script.js:62–83  ·  view source on GitHub ↗
(blob)

Source from the content-addressed store, hash-verified

60};
61
62const 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
85const storeFileInSWCache = async (blob) => {
86 try {

Callers 1

script.jsFile · 0.85

Calls 2

logMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected