FileSystemWritableFileStream Class

The state of a stream that writes a file (https://fs.spec.whatwg.org/#api-filesystemwritablefilestream), created by FileSystemFileHandle.CreateWritable: a buffer and a cursor. The buffer replaces the content of the file when the stream is closed (FileSystemWritableFileStream.Close); FileSystemWritableFileStream.Abort discards it. In the scripts, the FileSystemWritableFileStream interface is a WritableStream (Streams.js) whose underlying sink is this object.

public sealed class FileSystemWritableFileStream

Properties

NameDescription
IsClosedGets whether the stream was closed or aborted: its lock is released, and it cannot be written.
ModeGets the locking mode of the stream: see FileSystemCreateWritableOptions.Mode.

Gets whether the stream was closed or aborted: its lock is released, and it cannot be written.

public bool IsClosed { get; }

Property value

bool

  • Experimental (WEBPLATEXP0007)

Gets the locking mode of the stream: see FileSystemCreateWritableOptions.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
Abort()The abort algorithm of the stream: the buffer is discarded and the lock is released. Does nothing when the stream is closed.
Close()The close algorithm of the stream: the buffer replaces the content of the file, and the lock is released. The file that was removed meanwhile is not created again (a NotFoundError).
Seek(long)Moves the cursor (the "seek" command).
Truncate(long)Sets the size of the file (the "truncate" command): the file is truncated or grows with zeros, and a cursor after its end moves to its end.
Write(ReadOnlySpan<byte>, long?)Writes data at the position of the cursor, or at position (https://fs.spec.whatwg.org/#write-a-chunk), and moves the cursor after the data. The file grows with zeros when the position is after its end.

The abort algorithm of the stream: the buffer is discarded and the lock is released. Does nothing when the stream is closed.

public void Abort()

The close algorithm of the stream: the buffer replaces the content of the file, and the lock is released. The file that was removed meanwhile is not created again (a NotFoundError).

public void Close()

Moves the cursor (the "seek" command).

public void Seek(long position)

Parameters

position long

Sets the size of the file (the "truncate" command): the file is truncated or grows with zeros, and a cursor after its end moves to its end.

public void Truncate(long size)

Parameters

size long

Exceptions

QuotaExceededError
The new size exceeds the quota of the storage.

Write(ReadOnlySpan<byte>, long?)

FileSystemFileHandle.cs

Writes data at the position of the cursor, or at position (https://fs.spec.whatwg.org/#write-a-chunk), and moves the cursor after the data. The file grows with zeros when the position is after its end.

public void Write(ReadOnlySpan<byte> data, long? position = null)

Parameters

data ReadOnlySpan<byte>
position long?

Exceptions

QuotaExceededError
The write exceeds the quota of the storage.