Okio: Is there a way to get access to app private ...
# squarelibraries
x
Okio: Is there a way to get access to app private files directory on android with
FileSystem
? Always get
Copy code
Caused by: android.system.ErrnoException: open failed: EROFS (Read-only file system)
when I do this on
androidMain
Copy code
FileSystem.SYSTEM.sink("test.json".toPath)
1
s
Wanna try out https://google.github.io/modernstorage/storage/ that uses okio underneath?
x
is that multiplatform? my use-case is multiplatform
Turns out you need android context to get a file path to app files dir
Copy code
FileSystem.SYSTEM.sink("${context.filesDir.path}/test.json".toPath())
However, looks like encoders that use these sinks doesn't really work 🤔 not sure why - no exception is getting thrown
y
Not an answer, but you probably don't need the string template. / works on path as an operator.
x
Welp, turns out this was just my bad. I inspected the file directories and it was getting written just fine. The problem was just how I was subscribing to the updates on the start, and it was always emitting just null. This was simply fixed with just
Copy code
val updates: Flow<T?> get() = this.stateFlow
  .onStart { read() }
and added a test case for this with
Copy code
@Test
fun testUpdatesWithPreviouslyStoredValue() = runTest {
  FILE_SYSTEM.sink(filePath.toPath()).buffer().use { Json.encode(OREO, it) }
  val newStore: KStore<Pet> = store(filePath = filePath)
  newStore.updates.test {
    assertEquals(OREO, awaitItem())
  }
}
More in https://github.com/xxfast/KStore/commit/cca82cfd4c8d914812ee8a700a140a3d1caa687d
220 Views