Table of Contents

Class FileStream

Namespace
Sdl3Sharp.IO
Assembly
Sdl3Sharp.dll

A stream that is backed by a named file on the filesystem

public sealed class FileStream : Stream, IDisposable
Inheritance
FileStream
Implements
Inherited Members
Extension Methods

Constructors

FileStream(string, FileAccess, FileMode)

Creates a new FileStream for a specified file name, access, and mode

public FileStream(string fileName, FileAccess access, FileMode mode)

Parameters

fileName string

The name of the file to open

access FileAccess

The FileAccess value representing the access mode

mode FileMode

The FileMode value representing the file mode

Remarks

On Android, this can be used to open "content://" URIs. As a fallback, this will transparently open a matching fileName in the app's assets.

Exceptions

SdlException

The FileStream could not be created (check TryGet(out string?) for more information)

ArgumentException

The combination of access and mode is invalid

FileStream(string, FileAccess, FileMode, FileKind)

Creates a new FileStream for a specified file name, access, mode, and kind

public FileStream(string fileName, FileAccess access, FileMode mode, FileKind kind)

Parameters

fileName string

The name of the file to open

access FileAccess

The FileAccess value representing the access mode

mode FileMode

The FileMode value representing the file mode

kind FileKind

The FileKind value representing the file kind

Remarks

On Android, this can be used to open "content://" URIs. As a fallback, this will transparently open a matching fileName in the app's assets.

Exceptions

SdlException

The FileStream could not be created (check TryGet(out string?) for more information)

ArgumentException

The combination of access, mode, and kind is invalid

FileStream(string, string)

Creates a new FileStream for a specified file name and mode string

public FileStream(string fileName, string modeString)

Parameters

fileName string

The name of the file to open

modeString string

The mode string to use when opening the file

Remarks

The mode strings used by this method are roughly the same as the ones used by the C standard library's fopen function. You can use TryGetModeString(FileAccess, FileMode, out string?) or TryGetModeString(FileAccess, FileMode, FileKind, out string?) to construct valid mode strings.

On Android, this can be used to open "content://" URIs. As a fallback, this will transparently open a matching fileName in the app's assets.

Exceptions

SdlException

The FileStream could not be created (check TryGet(out string?) for more information)

Properties

AndroidAAsset

Gets the pointer to the Android NDK AAsset that the FileStream is using to access the filesystem

public nint AndroidAAsset { get; }

Property Value

nint

The pointer to the Android NDK AAsset that the FileStream is using to access the filesystem. This can be cast to an Android NDK AAsset*.

Remarks

If SDL uses some other method to access the filesystem, this property will not be set and returns default(nint).

See Also

FileDescriptor

Gets the file descriptor number that the FileStream is using to access the filesystem

public int FileDescriptor { get; }

Property Value

int

The file descriptor number that the FileStream is using to access the filesystem. This is a C file descriptor number.

See Also

StdioFile

Gets the pointer to the C standard library FILE that the FileStream is using to access the filesystem

public nint StdioFile { get; }

Property Value

nint

The pointer to the C standard library FILE that the FileStream is using to access the filesystem. This can be cast to a C standard library FILE*.

Remarks

If SDL uses some other method to access the filesystem, this property will not be set and returns default(nint).

NOTE: The value of this property is highly dependent on the C standard library and the compiler the underlying native SDL library was built with. Using that value without knowing these settings or using it on differing platforms may lead to at least undefined behavior or even result in a crash! Do not rely on the value of this property unless you really know what you are doing.

See Also

WindowsHandle

Gets the Windows HANDLE that the FileStream is using to access the filesystem

public nint WindowsHandle { get; }

Property Value

nint

The Windows HANDLE that the FileStream is using to access the filesystem. This can be cast to a Windows HANDLE.

Remarks

If SDL uses some other method to access the filesystem, this property will not be set and returns default(nint).

Methods

TryGetModeString(FileAccess, FileMode, FileKind, out string?)

Tries to get the mode string for the specified access, mode, and kind

public static bool TryGetModeString(FileAccess access, FileMode mode, FileKind kind, out string? modeString)

Parameters

access FileAccess

The FileAccess value representing the access mode

mode FileMode

The FileMode value representing the file mode

kind FileKind

The FileKind value representing the file kind

modeString string

The resulting mode string, when this method returns true; otherwise, null

Returns

bool

true, if the mode string was successfully retrieved; otherwise, false

Remarks

A mode string constructed by this method is roughly the same as the ones used by the C standard library's fopen function.

TryGetModeString(FileAccess, FileMode, out string?)

Tries to get the mode string for the specified access and mode

public static bool TryGetModeString(FileAccess access, FileMode mode, out string? modeString)

Parameters

access FileAccess

The FileAccess value representing the access mode

mode FileMode

The FileMode value representing the file mode

modeString string

The resulting mode string, when this method returns true; otherwise, null

Returns

bool

true, if the mode string was successfully retrieved; otherwise, false

Remarks

A mode string constructed by this method is roughly the same as the ones used by the C standard library's fopen function.