Table of Contents

Class File

Namespace
Sdl3Sharp.IO
Assembly
Sdl3Sharp.dll

Provides static methods to load data from files and save data into files

public static class File
Inheritance
File
Inherited Members

Methods

TryLoad(string, out NativeMemoryManager?)

Tries to load all the data from a specified file

public static bool TryLoad(string fileName, out NativeMemoryManager? data)

Parameters

fileName string

The file path to the file, where to read all available data from

data NativeMemoryManager

A NativeMemoryManager managing native memory containing all available data from the specified file, when this method returns true; otherwise, null

Returns

bool

true, if all available data from the specified file was succesfully read; otherwise, false (check TryGet(out string?) for more information)

Remarks

The resulting NativeMemoryManager should be disposed if the memory it's managing is no longer needed. That also frees the allocated memory.

This method is not threadsafe.

TryLoadAsync(string, AsyncIOQueue, object?)

Tries to load all the data from a specified file asynchronously

public static bool TryLoadAsync(string fileName, AsyncIOQueue queue, object? userdata = null)

Parameters

fileName string

The file path to the file, where to read all available data from

queue AsyncIOQueue

The AsyncIOQueue to add the asynchronous reading operation to

userdata object

User-defined data to associate with the asynchronous reading operation. This will be provided as the Userdata property's value of the AsyncIOOutcome returned by the operation.

Returns

bool

true, if the reading operation was initiated successfully; otherwise, false (check TryGet(out string?) for more information)

Remarks

This method returns as quickly as possible; it does not wait for the reading operation to complete. On a successful return, this work will continue in the background. If the work begins, even a failure is asynchronous: a failing return value from this method only means the reading operation couldn't get initiated.

This method will allocate the buffer to contain the file for you. Make sure to dispose the resulting AsyncIOOutcome to free that buffer when it's no longer needed.

The newly created asynchronous reading operation will be added to the specified queue.

TrySave(string, ReadOnlyNativeMemory)

Tries to save all specified data into a specified file

public static bool TrySave(string fileName, ReadOnlyNativeMemory data)

Parameters

fileName string

The file path to the file, where to write all available data into

data ReadOnlyNativeMemory

The memory buffer containing all the data to be written into the specified file

Returns

bool

true, if the data from the specified memory buffer was succesfully written into the specified file; otherwise, false (check TryGet(out string?) for more information)

Remarks

If data is invalid, no data will be written and this method returns false.

This method is not threadsafe.

TrySave(string, ReadOnlySpan<byte>)

Tries to save all specified data into a specified file

public static bool TrySave(string fileName, ReadOnlySpan<byte> data)

Parameters

fileName string

The file path to the file, where to write all available data into

data ReadOnlySpan<byte>

The ReadOnlySpan<T> containing all the data to be written into the specified file

Returns

bool

true, if all the data from the specified ReadOnlySpan<T> was succesfully written into the specified file; otherwise, false (check TryGet(out string?) for more information)

Remarks

This method is not threadsafe.

TrySave(string, void*, nuint)

Tries to save all specified data into a specified file

public static bool TrySave(string fileName, void* data, nuint size)

Parameters

fileName string

The file path to the file, where to write all available data into

data void*

A pointer to the unmanaged memory containing all the data to be saved into the stream

size nuint

The size, in bytes, of the data to be saved

Returns

bool

true if all the data from the specified unmanaged memory was successfully written into the specified file; otherwise, false (check TryGet(out string?) for more information)

Remarks

The unmanaged memory pointed to by data must be safely dereferencable for at least size bytes.

This method is not threadsafe.

TryUnsafeLoadAsync(string, AsyncIOQueue, void*)

Tries to load all the data from a specified file asynchronously

public static bool TryUnsafeLoadAsync(string fileName, AsyncIOQueue queue, void* userdata = null)

Parameters

fileName string

The file path to the file, where to read all available data from

queue AsyncIOQueue

The AsyncIOQueue to add the asynchronous reading operation to

userdata void*

A pointer to unmanaged user-defined data to associate with the asynchronous reading operation. This will be provided as the UnsafeUserdata property's value of the AsyncIOOutcome returned by the operation.

Returns

bool

true, if the reading operation was initiated successfully; otherwise, false (check TryGet(out string?) for more information)

Remarks

This method returns as quickly as possible; it does not wait for the reading operation to complete. On a successful return, this work will continue in the background. If the work begins, even a failure is asynchronous: a failing return value from this method only means the reading operation couldn't get initiated.

This method will allocate the buffer to contain the file for you. Make sure to dispose the resulting AsyncIOOutcome to free that buffer when it's no longer needed.

The unmanaged user-defined data pointed to by userdata must remain valid until the AsyncIOOutcome of the reading operation is disposed.

The newly created asynchronous reading operation will be added to the specified queue.