Table of Contents

Method LoadFromFile

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

LoadFromFile(string, LM, 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, 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

DataSource

A DataSource instance that lazily loads its content from the file.

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.