-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix build, remove expect object usages
- Loading branch information
Showing
11 changed files
with
118 additions
and
136 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
64 changes: 29 additions & 35 deletions
64
...tate/src/androidMain/kotlin/pro/respawn/flowmvi/savedstate/platform/FileAccess.android.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,50 +1,44 @@ | ||
package pro.respawn.flowmvi.savedstate.platform | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.File | ||
import java.io.InputStream | ||
import java.util.zip.GZIPInputStream | ||
import java.util.zip.GZIPOutputStream | ||
|
||
@PublishedApi | ||
internal actual object FileAccess { | ||
|
||
private fun File.outputStreamOrEmpty() = run { | ||
parentFile?.mkdirs() | ||
createNewFile() | ||
outputStream() | ||
} | ||
private fun File.outputStreamOrEmpty() = run { | ||
parentFile?.mkdirs() | ||
createNewFile() | ||
outputStream() | ||
} | ||
|
||
private fun InputStream.readOrNull() = bufferedReader().use { it.readText() }.takeIf { it.isNotBlank() } | ||
private fun InputStream.readOrNull() = bufferedReader().use { it.readText() }.takeIf { it.isNotBlank() } | ||
|
||
actual suspend fun writeCompressed(data: String?, path: String) = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return@withContext | ||
} | ||
file.outputStreamOrEmpty().let(::GZIPOutputStream).bufferedWriter().use { it.write(data) } | ||
internal actual suspend fun writeCompressed(data: String?, path: String) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return | ||
} | ||
return file.outputStreamOrEmpty().let(::GZIPOutputStream).bufferedWriter().use { it.write(data) } | ||
} | ||
|
||
actual suspend fun readCompressed(path: String): String? = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (!file.exists()) return@withContext null | ||
file.inputStream().let(::GZIPInputStream).readOrNull() | ||
} | ||
internal actual suspend fun readCompressed(path: String): String? { | ||
val file = File(path) | ||
if (!file.exists()) return null | ||
return file.inputStream().let(::GZIPInputStream).readOrNull() | ||
} | ||
|
||
actual suspend fun write(data: String?, path: String) = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return@withContext | ||
} | ||
file.outputStreamOrEmpty().bufferedWriter().use { it.write(data) } | ||
internal actual suspend fun write(data: String?, path: String) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return | ||
} | ||
return file.outputStreamOrEmpty().bufferedWriter().use { it.write(data) } | ||
} | ||
|
||
actual suspend fun read(path: String): String? = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (!file.exists()) return@withContext null | ||
file.inputStream().readOrNull() | ||
} | ||
internal actual suspend fun read(path: String): String? { | ||
val file = File(path) | ||
if (!file.exists()) return null | ||
return file.inputStream().readOrNull() | ||
} |
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
15 changes: 7 additions & 8 deletions
15
savedstate/src/commonMain/kotlin/pro/respawn/flowmvi/savedstate/platform/FileAccess.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,10 +1,9 @@ | ||
package pro.respawn.flowmvi.savedstate.platform | ||
|
||
@PublishedApi | ||
internal expect object FileAccess { | ||
|
||
suspend fun writeCompressed(data: String?, path: String) | ||
suspend fun readCompressed(path: String): String? | ||
suspend fun write(data: String?, path: String) | ||
suspend fun read(path: String): String? | ||
} | ||
internal expect suspend fun writeCompressed(data: String?, path: String) | ||
|
||
internal expect suspend fun readCompressed(path: String): String? | ||
|
||
internal expect suspend fun write(data: String?, path: String) | ||
|
||
internal expect suspend fun read(path: String): String? |
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
64 changes: 29 additions & 35 deletions
64
savedstate/src/jvmMain/kotlin/pro/respawn/flowmvi/savedstate/platform/FileAccess.jvm.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,50 +1,44 @@ | ||
package pro.respawn.flowmvi.savedstate.platform | ||
|
||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import java.io.File | ||
import java.io.InputStream | ||
import java.util.zip.GZIPInputStream | ||
import java.util.zip.GZIPOutputStream | ||
|
||
@PublishedApi | ||
internal actual object FileAccess { | ||
|
||
private fun File.outputStreamOrEmpty() = run { | ||
parentFile?.mkdirs() | ||
createNewFile() | ||
outputStream() | ||
} | ||
private fun File.outputStreamOrEmpty() = run { | ||
parentFile?.mkdirs() | ||
createNewFile() | ||
outputStream() | ||
} | ||
|
||
private fun InputStream.readOrNull() = bufferedReader().use { it.readText() }.takeIf { it.isNotBlank() } | ||
private fun InputStream.readOrNull() = bufferedReader().use { it.readText() }.takeIf { it.isNotBlank() } | ||
|
||
actual suspend fun writeCompressed(data: String?, path: String) = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return@withContext | ||
} | ||
file.outputStreamOrEmpty().let(::GZIPOutputStream).bufferedWriter().use { it.write(data) } | ||
internal actual suspend fun writeCompressed(data: String?, path: String) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return | ||
} | ||
return file.outputStreamOrEmpty().let(::GZIPOutputStream).bufferedWriter().use { it.write(data) } | ||
} | ||
|
||
actual suspend fun readCompressed(path: String): String? = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (!file.exists()) return@withContext null | ||
file.inputStream().let(::GZIPInputStream).readOrNull() | ||
} | ||
internal actual suspend fun readCompressed(path: String): String? { | ||
val file = File(path) | ||
if (!file.exists()) return null | ||
return file.inputStream().let(::GZIPInputStream).readOrNull() | ||
} | ||
|
||
actual suspend fun write(data: String?, path: String) = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return@withContext | ||
} | ||
file.outputStreamOrEmpty().bufferedWriter().use { it.write(data) } | ||
internal actual suspend fun write(data: String?, path: String) { | ||
val file = File(path) | ||
if (data == null) { | ||
file.delete() | ||
return | ||
} | ||
return file.outputStreamOrEmpty().bufferedWriter().use { it.write(data) } | ||
} | ||
|
||
actual suspend fun read(path: String): String? = withContext(Dispatchers.IO) { | ||
val file = File(path) | ||
if (!file.exists()) return@withContext null | ||
file.inputStream().readOrNull() | ||
} | ||
internal actual suspend fun read(path: String): String? { | ||
val file = File(path) | ||
if (!file.exists()) return null | ||
return file.inputStream().readOrNull() | ||
} |
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
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
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