Memory Stream¶
Import: import system.io;
MemoryStream¶
Seekable in-memory byte storage; closing rejects operations while retaining its data.
constructor¶
Creates an empty stream positioned at byte zero.
constructor¶
Copies bytes into independent storage and starts at byte zero.
tell¶
Returns the current byte position, or a closed-resource error.
length¶
Stored byte count; remains readable after closure.
read¶
Reads up to the requested size and advances the cursor; empty success indicates EOF. Negative sizes and reads after closure return errors.
write¶
Overwrites or appends bytes at the cursor and returns their count. A nonempty write beyond EOF fills the gap with zeros; size is limited to int range.
seek¶
Sets a byte position from zero through the maximum int, including beyond EOF. Invalid positions or closure return errors without changing the cursor.
to_bytes¶
Copies all stored bytes independently of the cursor; returns an error after closure.
flush¶
Validates that the stream is open; memory storage has no pending output.
close¶
Closes the stream idempotently; subsequent I/O returns a closed-resource error.
read_async¶
Checks cancellation, then performs an immediately ready in-memory read.
public async fun read_async(
max_bytes: int,
token: Option<CancellationToken> = Option.None
): Result<byte[], IoError>
write_async¶
Checks cancellation, then performs an immediately ready in-memory write.
public async fun write_async(
data: byte[],
token: Option<CancellationToken> = Option.None
): Result<int, IoError>
flush_async¶
Checks cancellation and validates that the stream is open.