Class File
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
fileNamestringThe file path to the file, where to read all available data from
dataNativeMemoryManagerA 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
fileNamestringThe file path to the file, where to read all available data from
queueAsyncIOQueueThe AsyncIOQueue to add the asynchronous reading operation to
userdataobjectUser-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
fileNamestringThe file path to the file, where to write all available data into
dataReadOnlyNativeMemoryThe 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
fileNamestringThe file path to the file, where to write all available data into
dataReadOnlySpan<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
fileNamestringThe file path to the file, where to write all available data into
datavoid*A pointer to the unmanaged memory containing all the data to be saved into the stream
sizenuintThe size, in bytes, of the data to be saved
Returns
- bool
trueif 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
fileNamestringThe file path to the file, where to read all available data from
queueAsyncIOQueueThe AsyncIOQueue to add the asynchronous reading operation to
userdatavoid*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.