https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
m

Michal Klimczak

04/03/2021, 4:57 PM
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.
s

Shakil Karim

04/03/2021, 5:16 PM
m

Michal Klimczak

04/03/2021, 5:23 PM
j

jw

04/03/2021, 6:25 PM
There's alpha releases of Okio. We need people to try it!
s

Shakil Karim

04/03/2021, 6:51 PM
Is there any example of using in KMP IOS project somewhere?
m

Michal Klimczak

04/03/2021, 6:52 PM
@jw where do I sign 🙂 3.0.0-alpha.2? are there any docs for that maybe?
j

jw

04/03/2021, 7:45 PM
Nope. Just the sources and tests. Or you can build the docs locally
👍 1
m

Michal Klimczak

04/03/2021, 8:00 PM
Hmm, I encountered the first error quite early - cannot load it:
Copy code
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
Copy code
commonMain -> implementation("com.squareup.okio:okio:3.0.0-alpha.2")
Okay, same for alpha.1 and 2.10.0...
Okay, nevermind :D
Copy code
implementation("com.squareup.okio:okio-multiplatform:3.0.0-alpha.2")
s

Shakil Karim

04/04/2021, 7:31 AM
@Michal Klimczak Does it work for you ?
m

Michal Klimczak

04/04/2021, 7:42 AM
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:
Copy code
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):
Copy code
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.
2 Views