whatwg / fs

File System Standard
https://fs.spec.whatwg.org/
Other
224 stars 19 forks source link

File and Directory Watch Functionality for the FileSystem API #123

Open WEBPerformace opened 1 year ago

WEBPerformace commented 1 year ago

Hello,

I'd like to suggest the addition of a feature to the FileSystem API that would allow watching for changes in files and directories.

I've seen it mentioned many times in the comments for issues in this repository that are not directly related to this problem, but I did not find a specific issue specifically for that.

This ability is an essential component in many types of applications, including IDEs, file managers, photo/video editors, ML dataset managers, syncing apps, and any web app that uses its own type of file browser.

The lack of a file system API that includes watching capabilities can limit the effectiveness of native web apps, pushing developers towards heavier client applications or Electron-based solutions. Many projects could become PWAs instead of heavier client applications if this feature was implemented.

There are workaround solutions currently being used, such as maintaining a local list of files and checking that against the directory listing or recursively iterating over all files. However, these solutions can be resource-intensive and aren't as efficient or reliable as native events could be.

The need for this feature extends beyond web apps. For example, a i've seen expressed interest in being notified when a device like a USB hard disk or pen is plugged into the system. Additionally, this would significantly benefit browser-based debuggers.

Most OSes include their APIs for watching file changes, such as ReadDirectoryChangesW and ReadDirectoryChangesExW on Windows or the File System Events API on MacOS. Leveraging these APIs could potentially reduce the time needed for implementation.

Thank you for considering this feature request. The addition of a file and directory watch functionality to the FileSystem API would undoubtedly empower developers to create more robust and efficient web apps.

a-sully commented 1 year ago

I agree this is useful! This idea has extensive prior discussion at https://github.com/WICG/file-system-access/issues/72, though that discussion is focused primarily on watching the local file system, while I believe this capability is also useful for the Bucket File System (a.k.a. Origin Private File System)

A proposal for a new FileSystemObserver interface is here: https://github.com/whatwg/fs/pull/124 (I expect to merge the PR soon)