1
- # Adding AccessHandles
1
+ # AccessHandle Proposal
2
2
3
3
## Authors:
4
4
@@ -114,7 +114,9 @@ API](https://docs.google.com/document/d/1cOdnvuNIWWyJHz1uu8K_9DEgntMtedxfCzShI7d
114
114
115
115
``` javascript
116
116
// 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' });
118
120
await handle .writable .getWriter ().write (buffer);
119
121
const reader = handle .readable .getReader ({mode: " byob" });
120
122
// Assumes seekable streams, and SharedArrayBuffer support are available
@@ -148,9 +150,9 @@ default reader and writer with a *seek()* method.
148
150
### Locking semantics
149
151
150
152
``` javascript
151
- const handle1 = await file .createAccessHandle ();
153
+ const handle1 = await file .createAccessHandle ({ mode : ' in-place ' } );
152
154
try {
153
- const handle2 = await file .createAccessHandle ();
155
+ const handle2 = await file .createAccessHandle ({ mode : ' in-place ' } );
154
156
} catch (e) {
155
157
// This catch will always be executed, since there is an open access handle
156
158
}
@@ -180,6 +182,30 @@ The exact name of the new methods hasn’t been defined. The current placeholder
180
182
for data access is * createAccessHandle()* and * createSyncAccessHandle()* .
181
183
* createUnflushedStreams()* and * createDuplexStream()* have been suggested.
182
184
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
+
183
209
### Assurances on non-awaited consistency
184
210
185
211
It would be possible to clearly specify the behavior of an immediate async read
@@ -196,11 +222,19 @@ interface FileSystemFileHandle : FileSystemHandle {
196
222
Promise<File> getFile();
197
223
Promise<FileSystemWritableFileStream> createWritable(optional FileSystemCreateWritableOptions options = {});
198
224
199
- Promise<FileSystemAccessHandle> createAccessHandle();
225
+ Promise<FileSystemAccessHandle> createAccessHandle(optional FileSystemFileHandleCreateAccessHandleOptions options = {} );
200
226
[Exposed=DedicatedWorker]
201
- Promise<FileSystemSyncAccessHandle> createSyncAccessHandle();
227
+ Promise<FileSystemSyncAccessHandle> createSyncAccessHandle(optional FileSystemFileHandleCreateAccessHandleOptions options = {});
228
+ };
229
+
230
+ dictionary FileSystemFileHandleCreateAccessHandleOptions {
231
+ AccessHandleMode mode;
202
232
};
203
233
234
+ // For more details and possible modes, see "Exposing AccessHandles on all
235
+ // filesystems" above
236
+ enum AccessHandleMode { "in-place" };
237
+
204
238
interface FileSystemAccessHandle {
205
239
// Assumes seekable streams are available. The
206
240
// Seekable extended attribute is ad-hoc notation for this proposal.
0 commit comments