For testing purposes, I’m adding the ability to re...
# multiplatform
j
For testing purposes, I’m adding the ability to read
*.json
files into kotlin strings. My project targets JVM, JS, and iOS. My approach was to create a common:
Copy code
expect fun readFileToString(file: String) : String?
And then implement actuals in each target. I have iOS and JVM working, but am not sure of the best way to implement the
actual
in JS. Here’s my JVM `actual`:
Copy code
import java.io.File

actual fun readFileToString(file: String) : String? {
    return File(file).readText(Charsets.UTF_8)
}
Anyone done something like this? I assume I’ll use
fs.fileReadSync:
but I’m not sure what I need to import to access that method?
n
You can convert a Promise into a suspending function:
Copy code
suspend fun <T> Promise<T>.await(): T = suspendCoroutine { cont -> 
    then({ cont.resume(it) }, { cont.resumeWithException(it) })                                                      
}
Then if there exists a thing in node that isn't in the stdlib for kotlin you can write a definition for it with
external fun
.