Table of Contents

Method LoadFromFileAsync

Namespace
LMKit.Data
Assembly
LM-Kit.NET.dll

LoadFromFileAsync(string, LM, bool, CancellationToken)

Asynchronously loads a DataSource from the specified file path by lazily loading its content. The file is opened in either read-only or read-write mode, and when read-write mode is used, the file stream remains open so that modifications to the DataSource are automatically synchronized back to the file. This lazy-loading design is particularly useful for large data sources where it is inefficient or unnecessary to load the entire content into memory at once.

public static Task<DataSource> LoadFromFileAsync(string path, LM model, bool readOnly, CancellationToken cancellationToken = default)

Parameters

path string

The path to the file from which to load the data source.

model LM

The language model used to assist with the deserialization of the data source.

readOnly bool

A flag indicating whether to open the file in read-only mode. If true, the file is opened as read-only; if false, the file is opened with read-write access, allowing the in-memory DataSource to persist changes back to the file.

cancellationToken CancellationToken

A token to monitor for cancellation requests during the asynchronous operation.

Returns

Task<DataSource>

A task representing the asynchronous operation, with the result being a DataSource instance that lazily loads its content.

Exceptions

ArgumentNullException

Thrown if path is null, empty, or consists solely of white-space characters.

IOException

Thrown if an I/O error occurs during file access.