You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
:: Writes the content of |buffer| into the file associated with |handle| with |options|.{{FilesystemReadWriteOptions/at}} as the offset.
1310
1331
</div>
1311
1332
1333
+
// TODO(fivedots): Is there a more formal way to describe the resutl of partial writes from the OS?
1334
+
1335
+
// TODO(fivedots): Figure out mechanism to prevent concurrent IO operations e.g. doing write() while a truncate() is executing in parallel.
1312
1336
<div algorithm>
1313
-
The <dfn method for=FileSystemSyncAccessHandle>write(|buffer|, {{FilesystemReadWriteOptions/at}}: |position|)</dfn> method, when invoked, must run
1337
+
The <dfn method for=FileSystemSyncAccessHandle>write(|buffer|, {{FilesystemReadWriteOptions}}: |options|)</dfn> method, when invoked, must run
1314
1338
these steps:
1315
1339
1316
-
// TODO(fivedots): fill in. Does this algorithm need to explicitly interact with storage quota?
1340
+
1. If [=this=].[=[[state]]=] is "closed", throw a {{InvalidStateError}}.
1341
+
1. Let |writePosition| be |options|.{{FilesystemReadWriteOptions/at}}.
1342
+
1. Let |fileContents| be a copy of [=this=].[=[[file]]=]'s [=file entry/binary data=].
1343
+
1. Let |oldSize| be |fileContents|'s [=byte sequence/length=].
1344
+
1. Let |data| be [=get a copy of the buffer source|a copy of=] |buffer|.
1345
+
1. If |writePosition| is larger than |oldSize|,
1346
+
append |writePosition| - |oldSize| `0x00` (NUL) bytes to the end of |fileContents|.
1347
+
1348
+
Note: Implementations are expected to behave as if the skipped over file contents
1349
+
are indeed filled with NUL bytes. That doesn't mean these bytes have to actually be
1350
+
written to disk and take up disk space. Instead most file systems support so called
1351
+
sparse files, where these NUL bytes don't take up actual disk space.
1352
+
1353
+
1. Let |head| be a [=byte sequence=] containing the first |writePosition| bytes of |fileContents|.
1354
+
1. Let |tail| be an empty [=byte sequence=].
1355
+
1. If |writePosition| + |data|.[=byte sequence/length=] is smaller than |oldSize|:
1356
+
1. Let |tail| be a [=byte sequence=] containing the last
1357
+
|oldSize| - (|writePosition| + |data|.[=byte sequence/length=]) bytes of |fileContents|.
1358
+
1. Let |newSize| be the [=byte sequence/length=] of the concatenation of |head|, |data| and |tail|.
1359
+
1. If |newSize| - |oldSize| exceeds the available [=storage quota=], throw a {{QuotaExceededError}}.
1360
+
1. Set [=this=].[=[[file]]=]'s [=file entry/binary data=] to the concatenation of |head|, |data| and |tail|.
1361
+
1. If the operations modifying the [=this=].[=[[file]]=]'s [=file entry/binary data=] in the previous steps
1362
+
failed:
1363
+
1. If there were partial modifications and the number of modified bytes is known,
1364
+
return the number of modified bytes.
1365
+
1. Else return 0.
1366
+
1. Return |data|.[=byte sequence/length=].
1317
1367
1318
1368
</div>
1319
1369
@@ -1324,6 +1374,7 @@ these steps:
1324
1374
:: Resizes the file associated with stream to be size bytes long. If size is larger than the current file size this pads the file with null bytes, otherwise it truncates the file.
1325
1375
</div>
1326
1376
1377
+
//TODO(fivedots):Make sure negative lengths are not allowed.
1327
1378
<div algorithm>
1328
1379
The <dfn method for=FileSystemSyncAccessHandle>truncate(|size|)</dfn> method, when invoked, must run
:: Ensures that the contents of the file associated with |handle| contain all the modifications done through {{FileSystemSyncAccessHandle/read()}} and {{FileSystemSyncAccessHandle/write()}}.
1405
+
:: Ensures that the contents of the file associated with |handle| contain all the modifications done through {{FileSystemSyncAccessHandle/write()}}.
1355
1406
</div>
1356
1407
1357
1408
<div algorithm>
@@ -1364,19 +1415,22 @@ these steps:
1364
1415
1365
1416
### The {{FileSystemSyncAccessHandle/close()}} method ### {#api-filesystemsyncaccesshandle-close}
1366
1417
1367
-
// TODO(fivedots): |fileHandle| is not properly defined here, consider adding an attribute to |handle|.
0 commit comments