You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The gist of it is, stream the file to disk using OPFS, then finally "download" the file via a blob URI (so that it ends up as a regular user-accessible file in their Downloads folder).
constroot=awaitnavigator.storage.getDirectory();consthandle=awaitroot.getFileHandle("file.txt",{create: true});constwritable=awaithandle.createWritable();// returns a FileSystemWritableFileStreamawaitwritable.write(newUint8Array(10));awaitwritable.write(newUint8Array(10));awaitwritable.close();constfile=awaithandle.getFile();// nb, this is a "File" object, not a regular blobconsturi=window.URL.createObjectURL(file);console.log(uri);// should be able to use browser.downloads.download() from webextension context (untested)consta=document.createElement("a");a.style.display="none";a.download="file.txt";a.href=uri;document.body.appendChild(a);a.click();// can't delete straight away! this is a race condition. not sure the best way to do this...//await root.removeEntry("file.txt");
(This is just a PoC and not a productionized impl)
The total free disk space required is double the actual size of the file, because it must temporarily exist in both OPFS and the user's Downloads folder.
It's hard to decide when to delete the file from OPFS once you're done with it, because you can't tell when the final download is complete. A fixed delay would probably be Good Enough but it'd still be a race condition.
Unknowns
I haven't tested in Safari at all
I haven't yet tested for sure that it can handle larger-than-RAM files, but in principle it should.
Given the significant Firefox-private-tab limitation I'd understand if you have no interest in integrating this (or as part of the ponyfill), but I figured I'd leave it here for anyone else looking for alternative approaches.
The text was updated successfully, but these errors were encountered:
The gist of it is, stream the file to disk using OPFS, then finally "download" the file via a blob URI (so that it ends up as a regular user-accessible file in their Downloads folder).
(This is just a PoC and not a productionized impl)
Pros
Cons
Unknowns
Given the significant Firefox-private-tab limitation I'd understand if you have no interest in integrating this (or as part of the ponyfill), but I figured I'd leave it here for anyone else looking for alternative approaches.
The text was updated successfully, but these errors were encountered: