Hello, I am trying to create a multiplatform image...
# ktor
d
Hello, I am trying to create a multiplatform image loading library, I use
ktor
for remote loading and
okio
for local loading(files). I want to have an interface for fetcher that returns a flow of
Loading(progress)
,
Success(something)
,
Error(throwable)
I am not sure what
something
should be to support both fetchers.
For remote loading I was thinking about using
ByteReadChannel
like in this library: https://github.com/alialbaali/Kamel/blob/main/kamel-core/src/commonMain/kotlin/io/kamel/core/fetcher/HttpFetcher.kt
I want to use `okio`'s
Path
to load from files and support multiplatform, but I don't know how to create a
ByteReadChannel
, I tried creating an extension for it based on
File.readChannel
, but some of the methods are internal and I gave up in the end.
a
You can create a channel from a
java.io.File
:
Copy code
File("/path").readChannel()
or use a writer to write data to a channel:
Copy code
val readChannel = GlobalScope.writer {
    // channel.writeFully()
    // channel.writeStringUtf8()
}.channel
d
It works for jvm, but not for other platforms, I tried making a new method based on that and change it to support
ByteReadChannel
but no luck
a
With a writer you can write data from any source.
d
I will try, thanks