# androidx.datastore.core

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript

## Interfaces

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/Closeable` | Datastore common version of java.io.Closeable | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionHandler` | CorruptionHandlers allow recovery from corruption that prevents reading data from the file (as indicated by a CorruptionException). | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataMigration` | Interface for migrations to DataStore. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` | DataStore provides a safe and durable way to store small amounts of data, such as preferences and application state. | Cmn android N JS |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/InterProcessCoordinator` | InterProcessCoordinator provides functionalities that support DataStore instances to coordinate the concurrent work running on multiple threads and multiple processes to guarantee its data consistency. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/ReadScope` | The scope used for a read transaction. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/Serializer` | The serializer determines the on-disk format and API for accessing it. | android |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/Storage` | Storage provides a way to create StorageConnections that allow read and write a particular type of data. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/StorageConnection` | StorageConnection provides a way to read and write a particular type of data. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/WriteScope` | The scope used for a write transaction. | Cmn |

## Classes

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore.Builder` | Builder for `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore`. | Cmn android N JS |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/FileStorage` | The Java IO File version of the Storage interface. | android |

## Exceptions

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/CorruptionException` | A subclass of IOException that indicates that the file could not be de-serialized due to data format corruption. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/IOException` | Common IOException to be defined in jvm and native code. | Cmn android N JS |

## Objects

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStoreFactory` | Public factory for creating DataStore instances. | Cmn android N JS |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/MultiProcessDataStoreFactory` |   | android |

## Type aliases

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/IOException` | Common IOException mapped to java.io.Exception in jvm code. | android |

## Top-level functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/InterProcessCoordinator` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/package-summary#createMultiProcessCoordinator(kotlin.coroutines.CoroutineContext,java.io.File)(context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html, file: https://developer.android.com/reference/java/io/File.html)` Create a coordinator for multiple process use cases. | android |
| `https://developer.android.com/reference/kotlin/androidx/datastore/core/InterProcessCoordinator` | `https://developer.android.com/reference/kotlin/androidx/datastore/core/package-summary#createSingleProcessCoordinator(java.io.File)(file: https://developer.android.com/reference/java/io/File.html)` Create a coordinator for single process use cases. | android |

## Extension functions summary

|---|---|---|
| `https://developer.android.com/reference/java/io/File.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 24) https://developer.android.com/reference/android/content/Context.html.https://developer.android.com/reference/kotlin/androidx/datastore/core/package-summary#(android.content.Context).deviceProtectedDataStoreFile(kotlin.String)(fileName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Generate the File object for DataStore for use during direct boot. | android |
| `suspend T` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/datastore/core/StorageConnection<T>.https://developer.android.com/reference/kotlin/androidx/datastore/core/package-summary#(androidx.datastore.core.StorageConnection).readData()()` | Cmn |
| `inline R` | `<T : https://developer.android.com/reference/kotlin/androidx/datastore/core/Closeable, R : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> T.https://developer.android.com/reference/kotlin/androidx/datastore/core/package-summary#(androidx.datastore.core.Closeable).use(kotlin.Function1)(block: (T) -> R)` Ensures a Closeable object has its close() method called at the end of the supplied block. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/datastore/core/StorageConnection<T>.https://developer.android.com/reference/kotlin/androidx/datastore/core/package-summary#(androidx.datastore.core.StorageConnection).writeData(kotlin.Any)(value: T)` | Cmn |

## Top-level functions

### createMultiProcessCoordinator

android Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/MultiProcessCoordinator.android.kt+function:createMultiProcessCoordinator) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

```
fun createMultiProcessCoordinator(context: CoroutineContext, file: File): InterProcessCoordinator
```

Create a coordinator for multiple process use cases.

| Parameters |
|---|---|
| `context: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html` | the coroutine context to be used by the `https://developer.android.com/reference/kotlin/androidx/datastore/core/MultiProcessCoordinator` for IO operations. |
| `file: https://developer.android.com/reference/java/io/File.html` | the File in which `https://developer.android.com/reference/kotlin/androidx/datastore/core/DataStore` stores the data. |

### createSingleProcessCoordinator

android Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/InterProcessCoordinator.jvmAndAndroid.kt+function:createSingleProcessCoordinator) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

```
fun createSingleProcessCoordinator(file: File): InterProcessCoordinator
```

Create a coordinator for single process use cases.

| Parameters |
|---|---|
| `file: https://developer.android.com/reference/java/io/File.html` | The canonical file managed by `https://developer.android.com/reference/kotlin/androidx/datastore/core/SingleProcessCoordinator` |

## Extension functions

### Context.deviceProtectedDataStoreFile

android Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/DeviceProtectedDataStoreFile.android.kt+function:deviceProtectedDataStoreFile) Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.2.0)

```
@RequiresApi(value = 24)
fun Context.deviceProtectedDataStoreFile(fileName: String): File
```

Generate the File object for DataStore for use during direct boot. If the provided context is a user encrypted context, it is converted to a DeviceProtectedStorageContext via `https://developer.android.com/reference/android/content/Context.html#createDeviceProtectedStorageContext()`.

The file is generated by calling `File(deviceProtectedContext.filesDir, "datastore/$fileName")`.

Do NOT use the file outside of DataStore.

The context used to get the files directory @fileName the file name

### StorageConnection.readData

Cmn Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/StorageConnection.kt+function:readData)

```
suspend fun <T : Any?> StorageConnection<T>.readData(): T
```

### T.use

Cmn Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/Closeable.kt+function:use) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

```
inline fun <T : Closeable, R : Any?> T.use(block: (T) -> R): R
```

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

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html` | any exceptions thrown in the block will propagate through this method. |

### StorageConnection.writeData

Cmn Artifact: [androidx.datastore:datastore-core](https://developer.android.com/jetpack/androidx/releases/datastore) [View Source](https://cs.android.com/search?q=file:androidx/datastore/core/StorageConnection.kt+function:writeData) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/datastore#1.1.0)

```
suspend fun <T : Any?> StorageConnection<T>.writeData(value: T): Unit
```