Skip to content

Commit e88a265

Browse files
committed
Add mode parameter
1 parent 81287f3 commit e88a265

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

AccessHandle.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adding AccessHandles
1+
# AccessHandle Proposal
22

33
## Authors:
44

@@ -114,7 +114,9 @@ API](https://docs.google.com/document/d/1cOdnvuNIWWyJHz1uu8K_9DEgntMtedxfCzShI7d
114114

115115
```javascript
116116
// In all contexts
117-
const handle = await file.createAccessHandle();
117+
// For details on the `mode` parameter see "Exposing AccessHandles on all
118+
// filesystems" below
119+
const handle = await file.createAccessHandle({ mode: 'in-place' });
118120
await handle.writable.getWriter().write(buffer);
119121
const reader = handle.readable.getReader({mode: "byob"});
120122
// Assumes seekable streams, and SharedArrayBuffer support are available
@@ -148,9 +150,9 @@ default reader and writer with a *seek()* method.
148150
### Locking semantics
149151

150152
```javascript
151-
const handle1 = await file.createAccessHandle();
153+
const handle1 = await file.createAccessHandle({ mode: 'in-place' });
152154
try {
153-
const handle2 = await file.createAccessHandle();
155+
const handle2 = await file.createAccessHandle({ mode: 'in-place' });
154156
} catch(e) {
155157
// This catch will always be executed, since there is an open access handle
156158
}
@@ -180,6 +182,30 @@ The exact name of the new methods hasn’t been defined. The current placeholder
180182
for data access is *createAccessHandle()* and *createSyncAccessHandle()*.
181183
*createUnflushedStreams()* and *createDuplexStream()* have been suggested.
182184

185+
### Exposing AccessHandles on all filesystems
186+
187+
This proposal only currently considers additions to OPFS, but it would probably
188+
be worthwhile to expand the new functionality to arbitrary file handles. While
189+
the exact behavior of *AccessHandles* outside of OPFS would need to be defined
190+
in detail, it's almost certain that the one described in this proposal should
191+
not be the default. To avoid setting it as such, we propose adding an optional
192+
*mode* string parameter to *createAccessHandle()* and
193+
*createSyncAccessHandle()*. Some possible values *mode* could take are:
194+
195+
* 'shared': The current behavior seen in File System Access API in general,
196+
there is no locking and modifications are atomic (meaning that they would
197+
only actually change the file when the *AccessHandle* is closed). This mode
198+
would be a safe choice as a default value.
199+
* 'exclusive': An exclusive write lock is taken on the file, but modifications
200+
are still atomic. This is a useful mode for developers that want to
201+
coordinate various writing threads but still want "all or nothing" writes.
202+
* 'in-place': The behavior described in this proposal, allowing developers to
203+
use high performance access to files at the cost of not having atomic writes.
204+
It's possible that this mode would only be allowed in OPFS.
205+
206+
Both the naming and semantics of the *mode* parameter have to be more concretely
207+
defined.
208+
183209
### Assurances on non-awaited consistency
184210

185211
It would be possible to clearly specify the behavior of an immediate async read
@@ -196,11 +222,19 @@ interface FileSystemFileHandle : FileSystemHandle {
196222
Promise<File> getFile();
197223
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {});
198224
199-
Promise<FileSystemAccessHandle> createAccessHandle();
225+
Promise<FileSystemAccessHandle> createAccessHandle(optional FileSystemFileHandleCreateAccessHandleOptions options = {});
200226
[Exposed=DedicatedWorker]
201-
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle();
227+
Promise<FileSystemSyncAccessHandle> createSyncAccessHandle(optional FileSystemFileHandleCreateAccessHandleOptions options = {});
228+
};
229+
230+
dictionary FileSystemFileHandleCreateAccessHandleOptions {
231+
AccessHandleMode mode;
202232
};
203233
234+
// For more details and possible modes, see "Exposing AccessHandles on all
235+
// filesystems" above
236+
enum AccessHandleMode { "in-place" };
237+
204238
interface FileSystemAccessHandle {
205239
// Assumes seekable streams are available. The
206240
// Seekable extended attribute is ad-hoc notation for this proposal.

0 commit comments

Comments
 (0)