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 FileSystemSyncAccessHandle

Properties

NameDescription
ModeGets 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

string

Methods

NameDescription
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.

Closes 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()

Transfers the modifications of the file to the storage (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-flush).

public void Flush()

Returns the size of the file, in bytes (https://fs.spec.whatwg.org/#dom-filesystemsyncaccesshandle-getsize).

public ulong GetSize()

Read(Span<byte>, FileSystemReadWriteOptions?)

FileSystemFileHandle.cs

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.

public long Read(Span<byte> buffer, FileSystemReadWriteOptions? options = null)

Parameters

buffer Span<byte>
options FileSystemReadWriteOptions?

Returns

long

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.

public void Truncate(ulong newSize)

Parameters

newSize ulong

Exceptions

QuotaExceededError
The new size exceeds the quota of the storage.

See also

Write(ReadOnlySpan<byte>, FileSystemReadWriteOptions?)

FileSystemFileHandle.cs

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.

public long Write(ReadOnlySpan<byte> buffer, FileSystemReadWriteOptions? options = null)

Parameters

buffer ReadOnlySpan<byte>
options FileSystemReadWriteOptions?

Returns

long

Exceptions

QuotaExceededError
The write exceeds the quota of the storage.