Is there a Multiplatform library that allows me to...
# multiplatform
c
Is there a Multiplatform library that allows me to persistently store large(-ish) ByteArrays (a few MBs) and have a simple key-value Flow-based API to check wether that key exists or the ByteArray under that key has been modified?
m
Which (multi)-platforms? Something that works on desktop for example does not necessarily work on WASM too.
c
I'm mostly looking for a mobile (Android & iOS) solution
a
sqldelight uses sqlite internally which supports blob ideally should support your use case
c
@Ahmed na I've also tried Room for my use case. Room or SQLDelight with BLOBs sounds like the thing I'm looking for, but in practice I ran into the issue that with BLOBs larger than 1MB i get an error telling me the SQLite CursorWindow size is too small. After some research, there seems to be a practical limit of 1MB for BLOBs in the underlying SQLite on Android, wether you use Room or SQLDelight. Also, for my use case, I don't necessarily want to query the whole ByteArray everytime something changes, I just want to be notified of changes. For a given key I want to be notified wether a ByteArray for that key has been created, deleted, or edited. Depending on circumstances I want to then be able to choose wether to load the ByteArray into memory. And all of on Android & iOS at the same time, if possible. Thinking about it, I think I'm looking for a simple Multiplatform FileObserver thing. Does something like that exists?
a
@Christian Gaisl file sdk will be kotlinx io but so far dont know if any filechange observer is there -------- One hacky idea for the db approach is storing the byteArray on multiple rows with same key name prefix
Copy code
file_a_1 -> [0-100]   ;1MB
file_a_2 -> [101-200] ;1MB
file_a_3 -> [101-200] ;0.5MB
then query back the file where
like  = file_a%
and merge into a ByteArray
c
Thanks, I'll have a look at that 👍
m
This limit of sqlite can be easily overcome. Just set the window size according to your needs. I am storing about 2GB in sqlite and most single blobs are much larger than 1MB.
Copy code
actual class DatabaseDriverFactoryImpl actual constructor() : DatabaseDriverFactory {

    private lateinit var activity: ComponentActivity

    fun init(activity: ComponentActivity) {
        this.activity = activity
    }

    override fun createDatabaseDriver(dbFilePath: String): SqlDriver {
        return AndroidSqliteDriver(AIPDatabase.Schema, activity.applicationContext, dbFilePath, windowSizeBytes = 50 * 1024 * 1024)
    }

}
💡 2