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
Chrome has a new filesystem API that could be of interest. This would allow save/open from user filesystem. IIRC, if you add a service worker (kinda scary) to make the PWA installable, you can keep user permissions between refreshes in indexdb.
I played around with this w/ CRA and Workbbox for a newsletter builder recently. Final FS api is pretty sweet:
/** * Open a handle to an existing file on the local file system. * * @return {!Promise<FileSystemFileHandle>} Handle to the existing file. */exportfunctiongetFileHandle(){consthandle=(windowasany).chooseFileSystemEntries();returnhandle;}/** * Create a handle to a new (text) file on the local file system. * * @return {!Promise<FileSystemFileHandle>} Handle to the new file. */exportfunctiongetNewFileHandle(){constopts={type: 'saveFile',accepts: [{description: 'Text file',extensions: ['txt'],mimeTypes: ['text/plain'],},],};consthandle=(windowasany).chooseFileSystemEntries(opts);returnhandle;}/** * Reads the raw text from a file. * * @param {File} file * @return {!Promise<string>} A promise that resolves to the parsed string. */exportfunctionreadFile(file: any){// If the new .text() reader is available, use it.if(file.text){returnfile.text();}// Otherwise use the traditional file reading technique.return_readFileLegacy(file);}/** * Reads the raw text from a file. * * @private * @param {File} file * @return {Promise<string>} A promise that resolves to the parsed string. */function_readFileLegacy(file: any){returnnewPromise(resolve=>{constreader=newFileReader();reader.addEventListener('loadend',e=>{consttext=(easany).srcElement.result;resolve(text);});reader.readAsText(file);});}/** * Writes the contents to disk. * * @param {FileSystemFileHandle} fileHandle File handle to write to. * @param {string} contents Contents to write. */exportasyncfunctionwriteFile(fileHandle: any,contents: any){// Create a writerconstwriter=awaitfileHandle.createWriter();// Make sure we start with an empty fileawaitwriter.truncate(0);// Write the full length of the contentsawaitwriter.write(0,contents);// Close the file and write the contents to diskawaitwriter.close();}
The text was updated successfully, but these errors were encountered:
Chrome has a new filesystem API that could be of interest. This would allow save/open from user filesystem. IIRC, if you add a service worker (kinda scary) to make the PWA installable, you can keep user permissions between refreshes in indexdb.
More here: https://web.dev/native-file-system/
I played around with this w/ CRA and Workbbox for a newsletter builder recently. Final FS api is pretty sweet:
The text was updated successfully, but these errors were encountered: