The Origin Private File System now works on Safari

57 points ChadNauseam_ 9 comments

The origin private file system (OPFS) is a storage endpoint provided as part of the File System API, which is private to the origin of the page and not visible to the user like the regular file system. It provides access to a special kind of file that is highly optimized for performance and offers in-place write access to its content.

– MDN

Essentially, OPFS gives webpages a directory that only they can write to and read from. These are real files written to a real directory on your computer and you can use it for all kinds of filesystem-ey things. (Although browsers add a bunch of buffers in between you and actually writing to the file, so from the webpage's perspective all writes are atomic and are slightly slower than writing natively would be.)

iOS and MacOS users on Developer Beta 2 of their respective platforms can now fully use this API since Apple has finally gotten around to finishing supporting it.

Since you're in this subreddit, you may want to do this from Rust (e.g. you're writing a webapp in Dioxsus). For that, you can use my library `opfs`. This is an announcement post for a new version of that library, which now has everything figured out for you, including working around some fun bugs recently introduced in Safari's WASM interpreter. The library also supports native platforms (using tokio instead of opfs when not compiling to wasm) and implements a virtual in-memory filesystem for tests. Enjoy!