Edwinexd / Edwinexd/sql-validator

Allow open & save to file (window.showOpenFilePicker)

Open
#13 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
4
Forks
2
PR merge metrics
No merged PRs in 30d

Description

There is a webapi in development that could be used to allow users to open/create a save file once and then repeatedly save to the same file without creating a bunch of dumps in the users download folder
https://developer.mozilla.org/en-US/docs/Web/API/Window/showOpenFilePicker#browser_compatibility

Example generated by Chatgpt:
```js
// Open file
async function openFile() {
const [fileHandle] = await window.showOpenFilePicker();
const file = await fileHandle.getFile();
const contents = await file.text();
console.log(contents); // Load file contents
return fileHandle; // Return handle for saving
}

// Save file
async function saveFile(fileHandle, data) {
const writableStream = await fileHandle.createWritable();
await writableStream.write(data); // Write new content
await writableStream.close();
}
```

Edit: might be more readily available then I initially thought https://developer.mozilla.org/en-US/docs/Web/API/FileSystemFileHandle

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.