DataStoreStorage

class DataStoreStorage<T : @Serializable Any>(dataStore: DataStore<T?>, file: File? = null) : Storage<T>

A repository for storing serializable objects in DataStore.

Parameters

T

The type of the object to be stored. Must be serializable.

dataStore

The DataStore instance to use for storing the object.

file

Optional file reference for physical file deletion. If provided, enables deleteFile() functionality.

Constructors

Link copied to clipboard
constructor(dataStore: DataStore<T?>, file: File? = null)

Functions

Link copied to clipboard
open suspend override fun delete()

Deletes the item from the DataStore by setting it to null. This clears the data content but does not delete the physical file. To delete the physical file, use deleteFile() instead.

Link copied to clipboard
open suspend override fun get(): T?

Retrieves the item from the DataStore.

Link copied to clipboard
open suspend override fun save(item: T)

Saves the given item in the DataStore.