FileSystemSyncAccessHandle Class
An access handle (https://fs.spec.whatwg.org/#api-filesystemsyncaccesshandle), created by FileSystemFileHandle.CreateSyncAccessHandle in a dedicated worker: it reads and writes a file in place, synchronously, and holds a lock on the file until it is closed.
public sealed class FileSystemSyncAccessHandleProperties
| Name | Description |
|---|---|
| Mode | Gets the locking mode of the access handle: see FileSystemCreateSyncAccessHandleOptions.Mode. |
- Experimental (WEBPLATEXP0007)
Gets the locking mode of the access handle: see FileSystemCreateSyncAccessHandleOptions.Mode.
[Experimental("WEBPLATEXP0007", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public string Mode { get; }Property value
Methods
| Name | Description |
|---|---|
| Close() | Closes the access handle (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-close): its lock is released, and its other methods throw an InvalidStateError. |
| Flush() | Transfers the modifications of the file to the storage (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-flush). |
| GetSize() | Returns the size of the file, in bytes (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-getsize). |
| Read(Span<byte>, FileSystemReadWriteOptions?) | Reads the file into buffer, from the position of the cursor or from FileSystemReadWriteOptions.At (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-read), moves the cursor after the bytes read and returns their number. |
| Truncate(ulong) | Sets the size of the file (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-truncate): the file is truncated or grows with zeros, and a cursor after its end moves to its end. |
| Write(ReadOnlySpan<byte>, FileSystemReadWriteOptions?) | Writes buffer into the file, at the position of the cursor or at FileSystemReadWriteOptions.At (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-write), moves the cursor after the bytes written and returns their number. The file grows with zeros when the position is after its end. |
Close()
FileSystemFileHandle.csCloses the access handle (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-close): its lock is released, and its other methods throw an InvalidStateError.
public void Close()Flush()
FileSystemFileHandle.csTransfers the modifications of the file to the storage (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-flush).
public void Flush()GetSize()
FileSystemFileHandle.csReturns the size of the file, in bytes (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-getsize).
public ulong GetSize()Read(Span<byte>, FileSystemReadWriteOptions?)
FileSystemFileHandle.csReads the file into buffer, from the position of the cursor or from FileSystemReadWriteOptions.At (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-read), moves the cursor after the bytes read and returns their number.
public long Read(Span<byte> buffer, FileSystemReadWriteOptions? options = null)Truncate(ulong)
FileSystemFileHandle.csSets the size of the file (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-truncate): the file is truncated or grows with zeros, and a cursor after its end moves to its end.
Parameters
newSizeulong
Exceptions
QuotaExceededError- The new size exceeds the quota of the storage.
See also
Write(ReadOnlySpan<byte>, FileSystemReadWriteOptions?)
FileSystemFileHandle.csWrites buffer into the file, at the position of the cursor or at FileSystemReadWriteOptions.At (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-write), moves the cursor after the bytes written and returns their number. The file grows with zeros when the position is after its end.
public long Write(ReadOnlySpan<byte> buffer, FileSystemReadWriteOptions? options = null)Parameters
bufferReadOnlySpan<byte>optionsFileSystemReadWriteOptions?
Returns
Exceptions
QuotaExceededError- The write exceeds the quota of the storage.