Created
June 15, 2023 07:18
-
-
Save gh640/5c584d7c2891939d432c88d820b6af98 to your computer and use it in GitHub Desktop.
Saving a string as a file in browser console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function: | |
async function saveFile(fh, content) { | |
const stream = await fh.createWritable(); | |
await stream.write(content, {type: "text/plain"}); | |
await stream.close(); | |
} | |
// Usage: | |
const content = 'Hello world'; | |
const fh = await window.showSaveFilePicker(); | |
await saveFile(fh, content); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See: