-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* close #28
- Loading branch information
Showing
5 changed files
with
79 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
object AppInfo { | ||
const val PACKAGE = "fun.kotlingang.kds" | ||
const val VERSION = "1.0.0" | ||
const val VERSION = "1.0.1" | ||
const val NAME = "Kotlin Data Storage" | ||
const val DESCRIPTION = "Multiplatform Coroutine-Based Kotlin Library for storing data via kotlinx.serialization" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
json/json-files/src/jsMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package `fun`.kotlingang.kds | ||
|
||
import `fun`.kotlingang.kds.file.CommonFile | ||
import `fun`.kotlingang.kds.storage.AsyncCommittableStorage | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.serialization.json.Json | ||
|
||
|
||
public actual open class KFileDataStorage private constructor ( | ||
json: Json, | ||
private val storage: JsonElementFileDataStorage | ||
) : KJsonDataStorage(json, storage), AsyncCommittableStorage { | ||
public actual constructor ( | ||
absolutePath: String, | ||
json: Json, | ||
scope: CoroutineScope | ||
) : this(json, JsonElementFileDataStorage(json, CommonFile(absolutePath), scope)) | ||
|
||
public actual constructor(json: Json, scope: CoroutineScope) : this ( | ||
absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "data.json").absolutePath, | ||
json, scope | ||
) | ||
|
||
public actual companion object { | ||
public actual fun ofName ( | ||
name: String, | ||
json: Json, | ||
scope: CoroutineScope | ||
): KFileDataStorage = KFileDataStorage ( | ||
absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "$name.json").absolutePath, | ||
json, scope | ||
) | ||
} | ||
|
||
final override fun commitBlocking(): Unit = storage.commitBlocking() | ||
final override fun launchCommit(): Unit = storage.launchCommit() | ||
final override suspend fun commit(): Unit = storage.commit() | ||
} |
42 changes: 37 additions & 5 deletions
42
json/json-files/src/jvmMain/kotlin/fun/kotlingang/kds/KFileDataStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
package `fun`.kotlingang.kds | ||
|
||
import `fun`.kotlingang.kds.file.CommonFile | ||
import `fun`.kotlingang.kds.storage.AsyncCommittableStorage | ||
import kotlinx.coroutines.* | ||
import kotlinx.serialization.json.Json | ||
import java.io.File | ||
|
||
|
||
@OptIn(DelicateCoroutinesApi::class) | ||
public fun KFileDataStorage ( | ||
file: File, | ||
json: Json = Json, | ||
scope: CoroutineScope = GlobalScope + SupervisorJob() | ||
): KFileDataStorage = KFileDataStorage(CommonFile(file), json, scope) | ||
public actual open class KFileDataStorage private constructor ( | ||
json: Json, | ||
private val storage: JsonElementFileDataStorage | ||
) : KJsonDataStorage(json, storage), AsyncCommittableStorage { | ||
public actual constructor ( | ||
absolutePath: String, | ||
json: Json, | ||
scope: CoroutineScope | ||
) : this(json, JsonElementFileDataStorage(json, CommonFile(absolutePath), scope)) | ||
|
||
public actual constructor(json: Json, scope: CoroutineScope) : this ( | ||
absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "data.json").absolutePath, | ||
json, scope | ||
) | ||
|
||
public constructor ( | ||
file: File, | ||
json: Json = Json, | ||
scope: CoroutineScope = GlobalScope + SupervisorJob() | ||
) : this(file.absolutePath, json, scope) | ||
|
||
public actual companion object { | ||
public actual fun ofName ( | ||
name: String, | ||
json: Json, | ||
scope: CoroutineScope | ||
): KFileDataStorage = KFileDataStorage ( | ||
absolutePath = CommonFile.HOME_DIR.join(path = "data").join(path = "$name.json").absolutePath, | ||
json, scope | ||
) | ||
} | ||
|
||
final override fun commitBlocking(): Unit = storage.commitBlocking() | ||
final override fun launchCommit(): Unit = storage.launchCommit() | ||
final override suspend fun commit(): Unit = storage.commit() | ||
} |