reactormonk
07/13/2022, 4:57 PMsuspend fun
which produces ByteArray
in 16 byte chunks. Reading them is kinda time-intensive, so I was wondering if there's a concept of a lazy channel of bytes, so I say "ready me X bytes" without it reading everything.Trevor Stone
07/13/2022, 5:01 PMreactormonk
07/13/2022, 5:02 PMJoffrey
07/13/2022, 5:03 PMFlow<ByteArray>
or similar. I'm not sure exactly what you're looking forTrevor Stone
07/13/2022, 5:04 PMreactormonk
07/13/2022, 5:10 PMsuspend fun read4Pages(location: Byte): ByteArray = ...
I'm currently using:
suspend fun readAll(from: Byte, to: Byte) = {
val reads = (to - from + 1) / 4
return (1..(reads)).flatMap {
val pageNr = it * 4
read4Pages(pageNr).toList()
}.toByteArray()
}
... which is quite slow, because it reads everything. Takes about ~ 3s. However, there's information in the pages on how far I have to read (currently it's about 20% of the total size), so I want to avoid reading everything.Trevor Stone
07/13/2022, 5:43 PMreactormonk
07/13/2022, 6:46 PMflatMap
signature requires it.read4Pages
is the base function which I wanna combine with something else to get a stream.uli
07/13/2022, 7:26 PMreactormonk
07/14/2022, 7:29 AM