WICG / file-system-access

Expose the file system on the user’s device, so Web apps can interoperate with the user’s native applications.
https://wicg.github.io/file-system-access/
Other
667 stars 66 forks source link

Nested entries #378

Open TheCymaera opened 2 years ago

TheCymaera commented 2 years ago

It is common for IDEs and game-engine editors to specify resources using URIs or file paths.

To access a deeply nested file, we need to call getFileHandle and getDirectoryHandle recursively. Each level is an asynchronous operation that needs to be run sequentially.

I propose that the getFileHandle, getDirectoryHandle, and removeEntry methods be overloaded to accept an array/iterable argument.

directory.getFileHandle(["path", "to", "file.txt"]);

Alternatively, file names should accept slashes as delimiters.

directory.getFileHandle("path/to/file.txt");

The options parameter should include a createRecursive flag to complement the create flag.

directory.getFileHandle(["path", "to", "file.txt"], { createRecursive: true });
// Creates:
// path/
// path/to/
// path/to/file.txt
guillaumebrunerie commented 1 year ago

You can easily implement it yourself, not sure if there would be an advantage in making the spec more complicated for that?

TheCymaera commented 1 year ago

Each level makes at least one file system call to check if the file exists. This takes anywhere between .2 to 1 milliseconds on the devices I've tried. The difference adds up quickly when processing multiple files.