File System Access

File System Access API and the Origin Private File System

The File System API works with FileSystemFileHandle and FileSystemDirectoryHandle objects. The File System Access API gets handles to the user's files through showOpenFilePicker(), showSaveFilePicker() and showDirectoryPicker(), so an editor can save back to the file it opened. It is Chromium-only (Chrome 86 1 ), needs a user gesture and throws AbortError on cancel, so it cannot run headless; elsewhere use <input type="file"> and downloads.

The origin private file system (OPFS) is Baseline Widely available: a sandboxed folder per origin, invisible to the user, with no prompts and the same quota as IndexedDB. In a dedicated worker, createSyncAccessHandle() gives fast in-place reads and writes, which is how SQLite 4,756 compiled to WebAssembly keeps a database on the web.

Writing and reading a file in the origin private file systemJavaScript
const root = await navigator.storage.getDirectory();        // this origin's private root
const dir = await root.getDirectoryHandle('notes', { create: true });
const handle = await dir.getFileHandle('todo.txt', { create: true });
const writable = await handle.createWritable();             // writes go to a swap file...
await writable.write('1. Buy milk\n');
await writable.close();                                     // ...committed atomically here
const file = await handle.getFile();                        // a File (a Blob) snapshot
console.log(file.size, JSON.stringify(await file.text()), (await root.resolve(handle)).join('/'));
Output
12 "1. Buy milk\n" notes/todo.txt