-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getting bytes as a stream/flow in common code #143
Comments
Hi @nxoim! Thanks for creating this issue. I'm currently working on a big update of FileKit. In the next version, PlatformFile on Android, Apple targets and JVM will be fully compatible with kotlinx-io. This way, it will be possible to read and write files like you want. Here is an extension that we will soon be able to do: public fun PlatformFile.asByteArrayFlow(chunkSize: Long): Flow<ByteArray> = flow {
val source = source() ?: return@flow
source.use { bufferedSource ->
val buffer = Buffer()
while (true) {
// Read up to chunkSize bytes into the buffer
bufferedSource.readAtMostTo(sink = buffer, byteCount = chunkSize)
if (buffer.size == 0L) break // End of stream
// Emit the contents of the buffer
emit(buffer.readByteArray())
// Clear the buffer for the next iteration
buffer.clear()
}
}
} If you want to try the next version of FileKit now, it's possible. I'm still working on it and moving things around. Also, there are some breaking changes with previous versions. In your settings.gradle.kts dependencyResolutionManagement {
repositories {
// ...
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") // Add this line
}
} In your build.gradle.kts, the package names have been changed. Also, update the version to 0.10.0-SNAPSHOT. // io.github.vinceglb:filekit-core is now:
implementation("io.github.vinceglb:filekit-dialog:0.10.0-SNAPSHOT")
// io.github.vinceglb:filekit-compose is now:
implementation("io.github.vinceglb:filekit-dialog-compose:0.10.0-SNAPSHOT") In your code, when you call FileKit classes, you'll probably need to fix the imports. Things are called almost as before. Here are some interesting files you can look at to understand how you can integrate with: The samples are updated if you want to see some examples: If you have any questions or comments, don't hesitate! |
this was INSANELY helpful, thank you so much. works great on android, have not tested on other platforms yet |
it would be nice to have an alternative to file.readBytes() in common code that returns a Flow<ByteArray> , in which each emmission is a chunk of data
The text was updated successfully, but these errors were encountered: