Open daxpedda opened 11 months ago
I guess this falls under #24.
My main concern is how the File System API you linked would map onto the std::fs
API. From a brief look at the API it looks like it doesn't map too well onto the file system of paths. I guess reading and writing would be relatively the same, but I'm concerned about how APIs like create_dir
or metadata
would map onto the web API.
I guess we could have a set of extension functions for opening the File
s, having the File
s open for reading and writing, and make all of the other APIs return "unsupported" errors. Does this make much sense?
I guess reading and writing would be relatively the same, but I'm concerned about how APIs like
create_dir
ormetadata
would map onto the web API.
I think we should use OPFS by default, see StorageManager.getDirectory()
. This would allow us to implement create_dir()
through FileSystemDirectoryHandle.getDirectoryHandle()
.
metadata
is also mostly covered, but we would have to create our own type that mirrors Std's Metadata
:
accessed
: not availablecreated
: not availablefile_type
/is_dir
/is_file
: FileSystemHandle.kind
(accessed through FileSystemFileHandle.getFile()
)len
: Blob.size
(inherited through File
, accessed through FileSystemFileHandle.getFile()
)modified
: File.lastModified
(accessed through FileSystemFileHandle.getFile()
)permissions
:
readonly
: FileSystemHandle.queryPermission()
(only supported on Chrome, but considering we are using OPFS it's no-op anyway)set_readonly
: FileSystemHandle.queryPermission()
(only supported on Chrome, but considering we are using OPFS it's no-op anyway)Will look into making a PR soon!
Would there be interest in adding support for Web through the File System API?
It would be pretty straightforward, as it's all natively async anyway and there would be no need to spawn any blocking threads. Probably the most interesting part is documentation and converting errors to
io::Error
.All major browsers already support this, except Safari which doesn't support writing files in async, but only in sync.
Happy to make the PR of course!