Skip to content

Instantly share code, notes, and snippets.

@gh640
Created June 15, 2023 07:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gh640/5c584d7c2891939d432c88d820b6af98 to your computer and use it in GitHub Desktop.
Saving a string as a file in browser console
// 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