-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WebIDLs for Filesystem Access API #3327
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise.
Needs a rebase though.
[Throws] | ||
Promise<File> getFile(); | ||
[Throws] | ||
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {}); | ||
[Exposed=DedicatedWorker, Throws] | ||
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These functions don't throw, their Promise
can reject with an exception, e.g. https://fs.spec.whatwg.org/#dom-filesystemfilehandle-getfile.
See https://searchfox.org/mozilla-central/source/dom/webidl/FileSystemFileHandle.webidl.
[Throws] | |
Promise<File> getFile(); | |
[Throws] | |
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {}); | |
[Exposed=DedicatedWorker, Throws] | |
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle(); | |
Promise<File> getFile(); | |
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {}); | |
[Exposed=DedicatedWorker] | |
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle(); |
[Throws] | ||
async iterable<USVString, FileSystemHandle>; | ||
|
||
[Throws] | ||
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {}); | ||
[Throws] | ||
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {}); | ||
|
||
[Throws] | ||
Promise<undefined> removeEntry(USVString name, optional FileSystemRemoveOptions options = {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, none of these should throw: https://searchfox.org/mozilla-central/source/dom/webidl/FileSystemDirectoryHandle.webidl#6.
[Throws] | |
async iterable<USVString, FileSystemHandle>; | |
[Throws] | |
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {}); | |
[Throws] | |
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {}); | |
[Throws] | |
Promise<undefined> removeEntry(USVString name, optional FileSystemRemoveOptions options = {}); | |
async iterable<USVString, FileSystemHandle>; | |
Promise<FileSystemFileHandle> getFileHandle(USVString name, optional FileSystemGetFileOptions options = {}); | |
Promise<FileSystemDirectoryHandle> getDirectoryHandle(USVString name, optional FileSystemGetDirectoryOptions options = {}); | |
Promise<undefined> removeEntry(USVString name, optional FileSystemRemoveOptions options = {}); |
Promise<undefined> write(FileSystemWriteChunkType data); | ||
Promise<undefined> seek(unsigned long long position); | ||
Promise<undefined> truncate(unsigned long long size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the spec all three can throw: https://streams.spec.whatwg.org/#writablestream-get-a-writer.
Not sure why Firefox doesn't have it: https://searchfox.org/mozilla-central/source/dom/webidl/FileSystemWritableFileStream.webidl.
Promise<undefined> write(FileSystemWriteChunkType data); | |
Promise<undefined> seek(unsigned long long position); | |
Promise<undefined> truncate(unsigned long long size); | |
[Throws] | |
Promise<undefined> write(FileSystemWriteChunkType data); | |
[Throws] | |
Promise<undefined> seek(unsigned long long position); | |
[Throws] | |
Promise<undefined> truncate(unsigned long long size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @daxpedda, I tried this in Chrome with this sample:
const storage = await window.navigator.storage.getDirectory();
const fileHandle = await storage.getFileHandle('test', { create: true });
const writable = await fileHandle.createWritable();
const writer = writable.getWriter(); // lock the stream
try {
console.log(writable.write('x')); // will fail to get a writer internally
} catch(e) {
// this won't run, instead the above promise will fail
console.log("CAUGHT");
console.log(e);
}
I know you linked docs about getting a writer for a writablestream - but it seems this write
function returns a promise which fails in the case that getting a writer fails due to the stream being locked, rather than throwing directly. Based on that, I think that like the Firefox webidls, that these should not have the [Throws]
annotation, because they give a failed promise instead of throwing when a writer can't be obtained for the stream.
What do you think? Am I missing something? :)
I'm happy to submit another PR to correct this if you agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a PR for this, can continue discussion there perhaps: #3435
Hopefully not a faux pas, but I wanted this too, including the PR feedback, so I made the changes for my personal use, and thought I'd offer it back here: #3427 |
Oh, tysm! I don't have much time to fix up this PR. I've been meaning to for a few days now. |
Closing in favor of #3427. |
IDL, MDN Docs
I'm pretty new to contributing to projects like this, please lmk if I did something wrong!
I followed the basic instructions listed in
web-sys
's Readme.As far as I can tell, the bindings are correct. However, I don't really know what I am doing, especially about
[Throws]
, so that assumption could be wrong.The Filesystem Access API seems to be pretty stable, however some browsers do not support it (i.e. Firefox) so I added it to unstable.