The origin private file system

thumbnail

Motivation

The File System Standard introduces an origin private file system (OPFS) that provides optimized performance for special types of files. This private file system is not visible to the user but is restricted to the origin of the page.

Traditional way of working with files on the web

Files on a computer are traditionally organized in folders that can be explored through the operating system's file explorer.

Modern way of working with files on the web

The user-visible file system allows users to access and manipulate files and folders on the web.

Restrictions of working with files on the web

Access to files and folders on the web is limited due to security restrictions.

Files as the foundation of processing

Files and folders serve as the foundation of processing on the web and are used for a variety of purposes.

The user-visible versus the origin private file system

The origin private file system is not visible to users and is private to the origin of a site.

Specifics of the origin private file system

The OPFS provides efficient handling of files and folders that are not visible to users.

Browser support

OPFS is supported by most modern web browsers.

Getting access to the root directory

To access files and folders in the OPFS, a root directory must be obtained.

Using the origin private file system on the main thread

Files and folders can be created, accessed, and deleted using methods such as "getFileHandle" and "removeEntry".

Resolving the path of a file or folder

The path of a file or folder can be resolved using the "resolve" method.

Checking if two file or folder handles point to the same file or folder

The "isEqual" method can determine if two file or folder handles point to the same file or folder.

Listing the contents of a folder

The "getDirectoryHandle" method can be used to list the contents of a folder.

Using the origin private file system in a Web Worker

Web Workers can access the OPFS synchronously using the "syncAccess" method.

Copying a file from the origin private file system to the user-visible file system

Files and folders can be copied from the OPFS to the user-visible file system using the "copyTo" method.

Debugging the origin private file system

Debugging can be performed using the "debugger" method.

Demo

A demo of the OPFS is available online.

Conclusions

OPFS provides optimized performance for handling files and folders that are not visible to users and is supported by most modern web browsers.