Package-level declarations

Types

Link copied to clipboard
interface Closeable

Datastore common version of java.io.Closeable

Link copied to clipboard
class CorruptionException(message: String, cause: Throwable? = null) : IOException

A subclass of IOException that indicates that the file could not be de-serialized due to data format corruption. This exception should not be thrown when the IOException is due to a transient IO issue or permissions issue.

Link copied to clipboard
interface DataMigration<T>

Interface for migrations to DataStore. Methods on this migration (shouldMigrate, migrate and cleanUp) may be called multiple times, so their implementations must be idempotent. These methods may be called multiple times if DataStore encounters issues when writing the newly migrated data to disk or if any migration installed in the same DataStore throws an Exception.

Link copied to clipboard
interface DataStore<T>

DataStore provides a safe and durable way to store small amounts of data, such as preferences and application state. It does not support partial updates: if any field is modified, the whole object will be serialized and persisted to disk. If you want partial updates, consider the Room API (SQLite).

Link copied to clipboard
expect object DataStoreFactory
actual object DataStoreFactory

Public factory for creating DataStore instances.

actual object DataStoreFactory

Public factory for creating DataStore instances.

Link copied to clipboard
class FileStorage<T>(serializer: Serializer<T>, produceFile: () -> File) : Storage<T>

The Java IO File version of the Storage interface. Is able to read and write T to a given file location.

Link copied to clipboard
expect open class IOException(message: String?, cause: Throwable?)

Common IOException to be defined in jvm and native code.

actual typealias IOException = IOException
actual open class IOException(message: String?, cause: Throwable?)

Common IOException mapped to a custom exception class in native code.

Link copied to clipboard
interface ReadScope<T> : Closeable

The scope used for a read transaction.

Link copied to clipboard
interface Serializer<T>

The serializer determines the on-disk format and API for accessing it.

Link copied to clipboard
interface Storage<T>

Storage provides a way to create StorageConnections that allow read and write a particular type of data. Storage is used to construct DataStore objects, and encapsulates all the specifics of the data format and persistence.

Link copied to clipboard

StorageConnection provides a way to read and write a particular type of data. StorageConnections are created from Storage objects.

Link copied to clipboard
interface WriteScope<T> : ReadScope<T>

The scope used for a write transaction.

Functions

Link copied to clipboard
suspend fun <T> StorageConnection<T>.readData(): T
Link copied to clipboard
inline fun <T : Closeable, R> T.use(block: (T) -> R): R

Ensures a Closeable object has its close() method called at the end of the supplied block.

Link copied to clipboard
suspend fun <T> StorageConnection<T>.writeData(value: T)