Thread
#multiplatform
    m

    Michal Klimczak

    1 year ago
    Tl;DR how to write a file (zip downloaded from network) on ios? okio files api seems to be just around the corner, but in the meantime I need to transfer bytes from
    ktor
    ByteReadChannel
    to ios
    NSOutputStream
    (I think) and I don't have an idea how to mix these apis. I'm also gonna need to then unzip it and move the files and dirs from the zip package to the local storage, but this is probably not really feasible in common code before okio files api, right? kotlinx-io seems to be dead.
    Shakil Karim

    Shakil Karim

    1 year ago
    m

    Michal Klimczak

    1 year ago
    j

    jw

    1 year ago
    There's alpha releases of Okio. We need people to try it!
    Shakil Karim

    Shakil Karim

    1 year ago
    Is there any example of using in KMP IOS project somewhere?
    m

    Michal Klimczak

    1 year ago
    @jw where do I sign 🙂 3.0.0-alpha.2? are there any docs for that maybe?
    j

    jw

    1 year ago
    Nope. Just the sources and tests. Or you can build the docs locally
    m

    Michal Klimczak

    1 year ago
    Hmm, I encountered the first error quite early - cannot load it:
    Unable to build Kotlin project configuration
    
    org.gradle.internal.resolve.ArtifactNotFoundException: Could not find okio-3.0.0-alpha.1-samplessources.jar (com.squareup.okio:okio:3.0.0-alpha.1).
    Searched in the following locations:
        <https://jcenter.bintray.com/com/squareup/okio/okio/3.0.0-alpha.1/okio-3.0.0-alpha.1-samplessources.jar>
    	at ...
    I don't really know why it tries to load it from jcenter, I even removed it entirely from respositories
    commonMain -> implementation("com.squareup.okio:okio:3.0.0-alpha.2")
    Okay, same for alpha.1 and 2.10.0...
    Okay, nevermind 😄
    implementation("com.squareup.okio:okio-multiplatform:3.0.0-alpha.2")
    Shakil Karim

    Shakil Karim

    1 year ago
    @Michal Klimczak Does it work for you ?
    m

    Michal Klimczak

    1 year ago
    Not really. I'm trying to do that on a background thread (using coroutines-native-mt), but can't access FileSystem.SYSTEM on that thread:
    Trying to access top level value not marked as @ThreadLocal or @SharedImmutable from non-main thread
    ...nor pass it from one thread to another (frozen mutation etc). I kinda managed to do that with something like (writing pseudocode from memory):
    withContext(Dispatchers.Main){
        FileSystem.SYSTEM.write(path){
            
           httpClient.get<HttpStatement>...{
               write(buffer)
           }
    
        }
    }
    And it created the file and allocated bytes, but something froze and I'm not even sure what is done on what thread here. @jw is it supposed to work on background thread in kotlin native? If so, how can I create the BufferedSink from FileSystem and then do the writing on bg thread? Something like
    Okio.buffer(FileSystem.SYSTEM.sink(path))
    only seems to be doable on main thread.