Method LoadFromFile
LoadFromFile(string, bool, CancellationToken)
Loads a DataSource from the specified file path by lazily loading its content. This method opens the file in either read-only or read-write mode, and when read-write mode is used, the backing file remains open so that the DataSource is only partially loaded into memory with additional content decoded on demand during the instance's life cycle. This lazy-loading approach is recommended for large data sources.
public static DataSource LoadFromFile(string path, bool readOnly, CancellationToken cancellationToken = default)
Parameters
pathstringThe path to the file from which to load the data source.
readOnlyboolA flag indicating whether to open the file in read-only mode. If
true, the file is opened as read-only; iffalse, the file is opened with read-write access, allowing the in-memory DataSource to persist changes back to the file.cancellationTokenCancellationTokenA token to monitor for cancellation requests during the asynchronous operation.
Returns
- DataSource
A DataSource instance that lazily loads its content from the file.
Exceptions
- ArgumentNullException
Thrown if
pathis null, empty, or consists solely of white-space characters.- IOException
Thrown if an I/O error occurs during file access.